Hello, I have a DataFrame with weather data for every day over a span of 10 years. I’m trying to calculate the monthly average temperature for the month of June of each year, so that I end up with 10 temperature values I can plot in a diagram. I have already converted the given date format into DateTime yyyy-mm-dd so that it is easier to work with.
I’ll try to replicate the code so far here:
using GLMakie
using DataFrames, CSV, Statistics
using Dates
#generate example dataset (not sure if this is how it works)
dates = DateTime(2011-01-01):Day(1):DateTime(2021-12-31)
values = rand(temperature(dates)) .*5
df = DataFrame(date = dates, temperature = values)
#create year, month and day columns
df.Year = Year.(df.date)
df.month = month.(df.month)
df.day = day.(df.day)
#I've managed to calculate the entirety of average temperatures over the 10 years as follows
Yrly_avg = combine(groupby(df, :Year)) do subdf
(; Year = first(subdf.Year),
AverageT = mean(skipmissing(subdf.temperatures)))
end
#... but I don't know how to alter this expression (if possible) to achieve the results I want
And this is where I get stuck. I’m aware there must be some way to filter the data by a specific month but I’m not sure how. And how to later calculate the average value for every month separately I’m also confused on. Any help is greatly appreciated ![]()