Groupby decimal days of year -- groubby("ddayofyear") #10068
Unanswered
geacomputing
asked this question in
Ideas
Replies: 1 comment
-
Very nice. You shouldn't need to use pandas here.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there.
I wanted to share an idea I had while working with 5-minute sampled weather data. I often use the groupby feature to analyze daily trends, but I wanted to find a way to include sub-hourly variability in my analysis. To do this, I wanted to use decimal days of the year instead of just the day of the year, and re-aggregate the data by hour of the day before computing the mean.
Having a 10 minutes sampling frequency:
I very often rely on the (amazing)
groupby
feature, specifically for doing daily trends:ds1.groupby('time.dayofyear').mean()
However, to avoid loosing sub-hourly variability and in this specific case,
I experimented with pandas Multiindexer and came up with a decimal dayofyear grouping method, which I call "ddayofyear". This method takes in high-resolution data, re-aggregates it to a meaningful resolution (such as [
hours, daysofyear
]), and computes the mean. I think this could be helpful to others and wanted to share it.I even think it could be refined and added to the existing groupers in xarray. The result of my method is a DataArray with a float coordinate representing the decimal day of the year.
The result is:
As you see the coordinate is no longer
int
, butfloat
(now decimal!).Happy coding,
Marco
The full code:
Beta Was this translation helpful? Give feedback.
All reactions