i have a data of;
profile_bucket | price
a 10
b 15
c 5
a 7
c 20
doing hist chart with this kind of data, but hist gives me a count of the values, but I need the sum of the price instead of the count. any ideas? Using py.
CodePudding user response:
df = pd.DataFrame({'profile_bucket':['a','b','c','a','c'], 'price':[10,15,5,7,20]})
df = df.groupby('profile_bucket').sum()
df = df.reset_index()
Output:
profile_bucket price
0 a 17
1 b 15
2 c 25
CodePudding user response:
Because histogram is to bin the data df['price']
and count the number of values in each bin, so if you want to sum the price, use bar chart instead:
d = {'profile_bucket': ['a','b','c','a','c'], 'price': [10,15,5,7,20]}
df = pd.DataFrame(data=d)
df2 = df.groupby('profile_bucket').sum()
df2.plot(kind='bar')
Output: