python pandas loc - filter for list of values
本问题已经有最佳答案,请猛点这里访问。
这应该是难以置信的容易,但我不能让它工作。
我想根据两个值筛选数据集。
1 2 3 4 5 6 7 8 | #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')] |
这必须是一个或声明吗?我可以在SQL中使用In来执行类似的操作?
有一个
1 | df.loc[df['channel'].isin(['sale','fullprice'])] |
按多个值筛选一列。