What is the quickest way to keep the original instances after they get aggregated with pandas.groupby
?
For example, given a dataframe df
entries column values
0 entry1 A 1.5
1 entry2 A 1.3
2 entry3 A 0.6
3 entry4 B 0.7
4 entry5 B 0.5
5 entry6 C 0.5
6 entry7 C 1.3
7 entry8 C 1.7
and running groupby
with mean
as aggregation, I would like to obtain something like the following
entries column mean
0 entry1 A 1.333
1 entry2 A 1.333
2 entry3 A 1.333
3 entry4 B 0.6
4 entry5 B 0.6
5 entry6 C 1.666
6 entry7 C 1.666
7 entry8 C 1.666
i.e. the repeated property for all the original instances.