Skip to content Skip to sidebar Skip to footer

Average Rows By Category Pandas

So I've got a DataFrame that looks like this: year geo_name adult_obesity some_college STATE_ABBR 0 2015 Autauga County, AL 0.313 NaN

Solution 1:

You can aggregate mean:

df = df.groupby(['year','STATE_ABBR'], as_index=False).mean()
print (df)
   year STATE_ABBR  adult_obesity  some_college
0  2013         AL            NaN           NaN
1  2014         AL            NaN           NaN
2  2015         AL       0.315667      0.524000
3  2016         AL       0.328000      0.540667
4  2017         AL       0.307500      0.613000

Post a Comment for "Average Rows By Category Pandas"