Pandas,使用条件语句过滤

2024-10-01 13:39:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据帧,需要根据条件进行过滤,如下所示。基本上,根据验证的速度进行过滤,除非它等于0,然后使用速度列

above_limit_speed = (df_cimbined_traff[df_cimbined_traff['Speed'] > df_cimbined_traff[df_cimbined_traff['Verified_speed']) > df_cimbined_traff['Postedspeed']].groupby('deploymentid')['Speed'].count().reset_index().rename(columns={'Speed': 'count_above_speed_limit'}).set_index('deploymentid')

示例数据帧

X_value - Speed - Verified_Speed - Post Speed
bluergh - 50 - 51 - 49
blasdu - 50 - 0 - 30
ausdas - 60-60-40

我已经尝试了上面的方法,以及它的各种变体,但是对于用Pandas在Python中处理这个问题的最佳方法感到非常困惑

更新

所以基本上

我想将post速度与验证速度进行比较,除非该速度等于零,我想将其与速度进行比较

非常感谢您的帮助

谢谢


Tags: 数据方法dfindexcount条件速度above