You could either use .str
again to get access to the string methods, or (better, IMHO) use case=False
to guarantee case insensitivity:
>>> df = pd.DataFrame({"body": ["ball", "red BALL", "round sphere"]})
>>> df[df["body"].str.contains("ball")]
body
0 ball
>>> df[df["body"].str.lower().str.contains("ball")]
body
0 ball
1 red BALL
>>> df[df["body"].str.contains("ball", case=False)]
body
0 ball
1 red BALL
>>> df[df["body"].str.contains("ball", case=True)]
body
0 ball
(Note that if you're going to be doing assignments, it's a better habit to use df.loc
, to avoid the dreaded SettingWithCopyWarning, but if we're just selecting here it doesn't matter.)
(Note #2: guess I really didn't need to specify 'round' there..)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…