What is the fastest way to select rows that contain a value in a Pandas dataframe?
You can testing the speed
boolfilter=(np.char.find(df.values.ravel().astype(str),'b')!=-1).reshape(df.shape).any(1)
boolfilter
array([False, True, True])
newdf=df[boolfilter]
One trivial possibility is to disable regex:
res = df[df.apply(lambda r: r.str.contains('b', case=False, regex=False).any(), axis=1)]
Another way using a list comprehension:
res = df[[any('b' in x.lower() for x in row) for row in df.values)]]