Identify Unique Combinations Of Values In Columns, Sum Another Column, And Count Number Of Appearances In Pandas
I have a DataFrame like so: import pandas as pd d = {'param_1': [1.0, 2.0, 1.0, 1.0, 3.0, 3.0, 1.0, 2.0, 2.0,], 'param_2': [0.02, 0.08, 0.02, 0.08, 0.08, 0.02, 0.02, 0.08, 0
Solution 1:
Try using df.groupby(['param_1', 'param_2', 'param_3', 'param_4']).agg(['sum', 'count'])
, which returns:
output_value
sum count
param_1 param_2 param_3 param_4
1.0 0.02 0.8 0 61.07 2
2.5 0 126.40 1
0.08 1.6 0 -56.32 1
2.0 0.02 0.8 0 325.40 1
0.08 1.6 1 -64.24 2
3.0 0.02 2.5 0 3.67 1
0.08 1.6 1 -10.36 1
You could unpack this DataFrame to print it out the way you'd prefer to see it, or just view it this way!
Post a Comment for "Identify Unique Combinations Of Values In Columns, Sum Another Column, And Count Number Of Appearances In Pandas"