【问题标题】:how to apply filter on one variable considering other two variable using python如何使用python考虑其他两个变量对一个变量应用过滤器
【发布时间】:2017-01-31 00:22:51
【问题描述】:
我的数据包含变量 participants、origin 和 score。我想要那些得分为greater than 60 的参与者和来源。这意味着过滤参与者我必须考虑来源和分数。我只能根据来源或分数进行过滤,但它不起作用。
如果有人可以帮助我,那就太好了!!!
【问题讨论】:
标签:
python
pandas
indexing
conditional-statements
tableau-api
【解决方案1】:
我觉得你可以用boolean indexing:
df = pd.DataFrame({'participants':['a','s','d'],
'origin':['f','g','t'],
'score':[7,80,9]})
print (df)
origin participants score
0 f a 7
1 g s 80
2 t d 9
df = df[df.score > 60]
print (df)
origin participants score
1 g s 80