我有一个数据帧,其输出是这样的:
fruit season
0 apples [plant, plant, plant]
1 oranges [harvest, plant, plant]
2 bananas [harvest, plant, harvest]
我想在季节列中搜索模式...
pattern = [harvest, plant, plant]
...因此它向我显示了一个过滤的数据框,其格式如下:
1 oranges [harvest, plant, plant]
答案 0 :(得分:0)
如果我没有误解,则希望显示具有该确切值的行: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html
pattern = ['harvest', 'plant', 'plant']
df.loc[df['season'] == pattern]