1df = pd.DataFrame(old_df.groupby(['groupby_attribute'])['mean_attribute'].mean())
2df = df.reset_index()
3df
1>>> n_by_state = df.groupby("state")["state"].count()
2>>> n_by_state.head(10)
3state
4AK 16
5AL 206
6AR 117
7AS 2
8AZ 48
9CA 361
10CO 90
11CT 240
12DC 2
13DE 97
14Name: last_name, dtype: int64
15
1>>> df = pd.DataFrame({'Animal': ['Falcon', 'Falcon',
2... 'Parrot', 'Parrot'],
3... 'Max Speed': [380., 370., 24., 26.]})
4>>> df
5 Animal Max Speed
60 Falcon 380.0
71 Falcon 370.0
82 Parrot 24.0
93 Parrot 26.0
10>>> df.groupby(['Animal']).mean()
11 Max Speed
12Animal
13Falcon 375.0
14Parrot 25.0
15
1>>>> df.columns = ['min satmtmid', 'max satmtmid', 'min satvrmid', 'max satvrmid', 'mean ugds']>>> df.head()