我正在创建3熊猫数据帧的基础上一个原始熊猫数据帧。我已经计算出标准偏差。在
#Mean
stats_over_29000_mean = stats_over_29000['count'].mean().astype(int)
152542个
^{pr2}$54313个
stats_over_29000_first_std = stats_over_29000_mean + stats_over_29000_count_between_std
206855号
stats_over_29000_second_std = stats_over_29000_first_std + stats_over_29000_count_between_std
261168个
stats_over_29000_third_std = stats_over_29000_second_std + stats_over_29000_count_between_std
315481号
这样可以从df中获取2个std下的所有行
#Select all rows where count is less than 2 standard deviations
stats_under_2_stds = stats_over_29000[stats_over_29000['count'] < stats_over_29000_second_std]
接下来,我想从df中选择所有行,其中>;=2 std且小于3 std
我试过:
stats_2_and_over_under_3_stds = stats_over_29000[stats_over_29000['count'] >= stats_over_29000_second_std < stats_over_29000_third_std]
以及
stats_2_and_over_under_3_stds = stats_over_29000[stats_over_29000['count'] >= stats_over_29000_second_std && < stats_over_29000_third_std]
但两者似乎都不管用。在
这是您在两个条件下过滤df的方法:
df = pd.DataFrame([[1,2],[1,3],[1,5],[1,8]],columns=['A','B'])
res = df[(df['B']<8) & (df['B']>2)]
结果:
就您而言:
^{pr2}$相关问题 更多 >
编程相关推荐