I created a dataframe using groupby
and pd.cut
to calculate the mean, std and number of elements inside a bin. I used the agg()
and this is the command I used:
df_bin=df.groupby(pd.cut(df.In_X, ranges,include_lowest=True)).agg(['mean', 'std','size'])
df_bin looks like this:
X Y
mean std size mean std size
In_X
(10.424, 10.43] 10.425 NaN 1 0.003786 NaN 1
(10.43, 10.435] 10.4 NaN 0 NaN NaN 0
I want to drop the rows of only when I encounter a NaN case. I want to create a new df_bin, without the NaN occurrences. I've tried:
df_bin=df_bin['X', 'mean'].dropna()
But this drops all other columns of df_bin and keep only one column.