Reputation: 97
I have a dataframe like this
block_name
['循环经济']
['3D打印']
['再生经济']
Now I want get the data with block_name
contains '经济'
words.
The result that I want is:
block_name
['循环经济']
['再生经济']
And I tried this:
df = df[('经济' in df['block_name'])]
And this:
df = df[(df['block_name'].find('经济') != -1)]
But they don't work.
How should I do this result like the SQL's like "%经济%"
?
Upvotes: 0
Views: 295
Reputation: 142651
Use .str.contains()
import pandas as pd
df = pd.DataFrame(['循环经济', '3D打印', '再生经济'], columns=['block_name'])
print df[df['block_name'].str.contains('经济')]
Upvotes: 1