I am creating 3 pandas dataframes based off of one original pandas dataframe. I have calculated standard deviations from the norm.
#Mean
stats_over_29000_mean = stats_over_29000['count'].mean().astype(int)
152542
#STDS
stats_over_29000_count_between_std = stats_over_29000_std - stats_over_29000_mean
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
This works to get all rows from df under 2 stds
#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]
Next I would like to select all rows from df where >=2 stds and less than 3 stds
I have tried:
stats_2_and_over_under_3_stds = stats_over_29000[stats_over_29000['count'] >= stats_over_29000_second_std < stats_over_29000_third_std]
and
stats_2_and_over_under_3_stds = stats_over_29000[stats_over_29000['count'] >= stats_over_29000_second_std && < stats_over_29000_third_std]
But neither seem to work.
This is how you filter on df with 2 conditions :
df = pd.DataFrame([[1,2],[1,3],[1,5],[1,8]],columns=['A','B'])
res = df[(df['B']<8) & (df['B']>2)]
result :
A B
1 1 3
2 1 5
In your case :
stats_2_and_over_under_3_stds = stats_over_29000[(stats_over_29000['count'] >= stats_over_29000_second_std) & (stats_over_29000['count'] < stats_over_29000_third_std)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With