pandas:使用运算符链接过滤DataFrame行在大部分操作pandas可以与运营商链接(来完成groupby,aggregate,apply,等),但我发现过滤行的唯一方法是通过正常的托架索引df_filtered = df[df['column'] == value]这是没有吸引力的,因为它需要df在能够过滤其值之前分配给变量。有更像以下的东西吗?df_filtered = df.mask(lambda x: x['column'] == value)
3 回答

慕运维8079593
TA贡献1876条经验 获得超5个赞
我会通过将掩码函数概括为:
def mask(df, f): return df[f(df)]
然后你可以做的事情:
df.mask(lambda x: x[0] < 0).mask(lambda x: x[1] > 0)
添加回答
举报
0/150
提交
取消