pandas groupby

df = pd.DataFrame(old_df.groupby(['groupby_attribute'])['mean_attribute'].mean())
df = df.reset_index()
df

Here is what the above code is Doing:
1. We’re grouping the dataframe by the groupby_attribute column.
2. We’re calculating the mean of the mean_attribute column.
3. We’re resetting the index of the dataframe.

The output of the code is a dataframe that looks like this:

groupby_attribute mean_attribute
0 0 0.5
1 1 0.5
2 2 0.5
3 3 0.5
4 4 0.5
5 5 0.5
6 6 0.5
7 7 0.5
8 8 0.5
9 9 0.5