什么是相当于R的熊猫基于逻辑条件获取子集?

时间:2017-04-21 08:28:28

标签: python r pandas indexing logical-operators

我想计算从r到pandas的等价物:

df$received[df$gender == 'F']

在熊猫中,如果我使用:

df['received'][df['gender'] == 'F']

它不起作用。

或者如果我尝试:

df['received'] & df['gender'] == 'F'

它给了我:unsupported operand type(s) for &: 'float' and 'bool'

1 个答案:

答案 0 :(得分:1)

您似乎需要locboolean indexing

outerbag = load 'file location ' using PigStorage(',') as (eid,edetails);
innerbag = FOREACH outerbag GENERATE eid, FLATTEN(STRSPLIT(edetails,'\t'));
dump innerbag;

样品:

df.loc[df['gender'] == 'F', 'received']
相关问题