Reputation: 1
I'm trying to sum the variable "Hill-Burton Funds", grouping by "stateyear":
ds['Hill-Burton Funds'].replace(",", "")
ds['Hill-Burton Funds'].astype(str).astype(int)
ds['hbfunds'] = ds.groupby(['stateyear'])['Hill-Burton Funds'].sum()
Despite first converting "Hill-Burton Funds" from an object to an integer, when I use sum() it is returning the variable ("hbfunds") that simply aggregates the numbers together instead of adding them(ex. 2000 and 2001 are becoming 20002001 instead of 4001). Please any help is appreciated!
Upvotes: 0
Views: 35
Reputation: 152
Use:
ds['Hill-Burton Funds'] = ds['Hill-Burton Funds'].replace(",", "").astype(str).astype(int)
ds['hbfunds'] = ds.groupby(['stateyear'])['Hill-Burton Funds'].sum()
Upvotes: 1