【发布时间】:2018-01-29 21:59:15
【问题描述】:
这应该非常简单,但我无法让它工作。
我想根据两个或多个值过滤我的数据集。
#this works, when I filter for one value
df.loc[df['channel'] == 'sale']
#if I have to filter, two separate columns, I can do this
df.loc[(df['channel'] == 'sale')&(df['type']=='A')]
#but what if I want to filter one column by more than one value?
df.loc[df['channel'] == ('sale','fullprice')]
这必须是 OR 语句吗?我可以使用 in? 在 SQL 中执行类似操作?
【问题讨论】:
-
df.loc[df['channel'].isin(['sale','fullprice'])]
标签: python pandas filter pandas-loc