Reputation: 301
I have a daily time series of sea surface temperature from MODIS/Aqua sensor, starting in 2002 until 2020:
data['Image_Datetime'] = pd.to_datetime(data['Image_Datetime'], format='%Y-%m-%d %H:%M:%S')
data = data.set_index('Image_Datetime')
data.head()
I want to group all data correspondent to the summer period (December, January and February months), so then I can analyse just the temperature variations over a single season. I know this should be more or less simple, but I've been searching for a solution and none of them seems quite intuitive using only pandas.
Upvotes: 1
Views: 601
Reputation: 93181
You must live in the southern hemisphere for summer to take place in December.
Try this:
season = data['Image_Datetime'].dt.month.map(lambda x: 'Summer' if x in [12, 1, 2] else 'Winter')
# Mean temperature by season
data.group_by(season)['Temperature'].mean()
Upvotes: 1