I am wanting to extract the following:
ID | Name | Rating |
---|---|---|
123 | Red | 5 |
123 | Red | 4 |
123 | Red | 3 |
123 | Red | 5 |
123 | Red | 4 |
123 | Red | 3 |
456 | Blue | 8 |
456 | Blue | 4 |
456 | Blue | 3 |
789 | Yellow | 6 |
789 | Yellow | 8 |
And basically return this:
ID | Name | Rating | Count |
---|---|---|---|
123 | Red | 4 | 6 |
456 | Blue | 5 | 3 |
789 | Yellow | 7 | 2 |
(ID and Name have been consolidated, rating is returning and average, and there is also a value count of the previously unique rows)
I have tried all manner of things with pandas.groupy but it doesn't seem to like this number of columns... Best I have managed is the following:
newtable = data.groupby('Name', as_index=False, sort=False)['Rating'].mean()
If anyone has any suggestions it would be greatly appreciated!