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())
                             AB2016-09-2319:36:0024.13333333.8888892016-09-2319:37:0024.10000034.000000

Another solution with groupby:

print (df.groupby([pd.TimeGrouper('1Min')]).mean())
                             AB2016-09-2319:36:0024.13333333.8888892016-09-2319:37:0024.10000034.000000

Post a Comment for "Pandas Groupby Return Average But! Exclude Nan"