Skip to content
Advertisement

How to select specific rows in a dataframe, group them and find the sum using python?

Here is some example data:

JavaScript

How can I create a new dataframe which groups the months into seasons and find the total sum of each season frequency, while the output is still a dataframe?

I would like something like this: (Winter is where Month = 12, 1, 2)(Spring is where Month = 3, 4, 5)(etc….)

JavaScript

I have tried to select the rows and concatenate them to start with but I keep getting errors unfortunately.

Advertisement

Answer

You can create a new column with seasons and group on that column:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement