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

## Question:

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?

## Answers:

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'].dt.day`

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()
```

or

```
per_day_median_temp = df.groupby('day').median()
```