I've got a dataset of transactions that i'm trying to summarize by year but when i run the output is the individual amounts by transaction. I've imported a csv into into python using pd.read_csv and cleaned up a few of the columns in the dataframe as well as adding new ones.
I'm using the following code that's generating the output below
df['Year'] = df['Date'].dt.year
df.groupby(df['Year'])['revenue'].agg(['sum'])
OUTPUT
Year Sum
2015 1203.21 1732.12 2551.01 1733.12 1323.44
2016 3203.21 1532.12 4431.01 1433.12 7323.44
2017 2203.21 122.12 131.01 1293.12 4223.44
2018 6203.21 232.12 1131.01 1533.12 4323.44
I have the following line of code to convert 'revenue' from string to float
pd.to_numeric(df['revenue'])
Year, Date and revenue are all columns in my dataframe. I want to be able to have one total for each year above as opposed to seeing the value of the individual transactions. Thanks.