Skip to content Skip to sidebar Skip to footer

Pandas Groupby Return Average BUT! Exclude NaN

So Im trying to make sense of the pandas groupby function and to reduce a large data frame I have. Here is an example: A B 2016-09-23 19:36:08+0

Solution 1:

I think you need resample with Resampler.mean, which compute mean of groups, excluding missing values:

print (df.resample('1Min').mean())
                             A          B
2016-09-23 19:36:00  24.133333  33.888889
2016-09-23 19:37:00  24.100000  34.000000

Another solution with groupby:

print (df.groupby([pd.TimeGrouper('1Min')]).mean())
                             A          B
2016-09-23 19:36:00  24.133333  33.888889
2016-09-23 19:37:00  24.100000  34.000000

Post a Comment for "Pandas Groupby Return Average BUT! Exclude NaN"