Python Forum
How to calculate percentage change sum (Mean) by group
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to calculate percentage change sum (Mean) by group
#1
Hi,

I have below DataFrame:

A 1.2  3.6
B 2.6  3.8 
A 1.5  2.1
B 2.0  2.9
C 2.4  3.5
H 4.1  2.9
C 5.9  9.3
A 2.9  8.3
B 8.7  5.6
H 2.9  7.3
H 3.6  1.9
B 2.3  1.0
A 7.1  2.3
I use blow code:
import pandas as pd

d = {'col1': ['B','A','B','C','H','C','A','B','H','H','B','B'],'col2': [2.6,1.5,2.0,2.4,4.1,5.9,2.9,8.7,2.9,3.6,2.3,2.3], 'col3': [3.8,2.1,2.9,3.5,2.9,9.3,8.3,5.6,7.3,1.9,1,1]}
df = pd.DataFrame(data=d)
df_avg=df.groupby(['col1']).mean() # this line works
df_pct=df.groupby(['col1']).pct_change.sum()
AttributeError: 'function' object has no attribute 'sum'
Reply


Messages In This Thread
How to calculate percentage change sum (Mean) by group - by SriRajesh - Jan-07-2019, 01:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,524 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  Formatting a Decimal to a Percentage dgrunwal 2 4,657 Jun-05-2020, 03:59 PM
Last Post: bowlofred
  How to calculate unique rows column sum and percentage SriRajesh 4 3,496 Feb-12-2020, 02:21 PM
Last Post: SriRajesh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020