Skip to content
Advertisement

Compute daily climatology using pandas python

I am trying to use pandas to compute daily climatology. My code is:

JavaScript

cum_data is the data frame containing daily dates from 1st Jan 1950 to 31st Dec 1953. I want to create a new vector of length 365 with the first element containing the average of rand_data for January 1st for 1950, 1951, 1952 and 1953. And so on for the second element…

Any suggestions how I can do this using pandas?

Advertisement

Answer

You can groupby the day of the year, and the calculate the mean for these groups:

JavaScript

However, you have the be aware of leap years. This will cause problems with this approach. As alternative, you can also group by the month and the day:

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