Calculate mean/median of values in a column based on dates of another column using Python


I have a dataframe consisting of temperature values on one column, and the corresponding dates on another column.

The dataframe has a time period of 7 days, with measurements taken every minute, the problem is that I don’t know how to calculate the mean/median of the temperature and see the output per day.

Any thoughts?

The data looks like this

Asked By: sunter



Firstly, make sure that the ‘Timestamp_0’ colum is in datetime format. df.Timestamp_0 = pd.to_datetime(df.Timestamp_0)
Then, create a column of day: df['day'] = df['Timestamp_0']

Then group the Temperature values by that newly created column and apply either mean or median function:

per_day_mean_temp = df.groupby('day').mean()


per_day_median_temp = df.groupby('day').median()
Answered By: nick sofias
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.