0

I have one csv data that has several variables as a daily time series. But there are multiple values for one day. I need to calculate daily averages of temperatures from these multiple values for the entire period.

CSV file is stored here: https://drive.google.com/file/d/1zbojEilckwg5rzNfWtHVF-wu1f8d9m9J/view?usp=sharing

When you filtered daily, you can see 27 different values for each day.

I can filter for each day and take averages like:

inpcsvFile = 'C:/.../daily average - one day has multiple values.csv'
df = pd.read_csv(inpcsvFile)
df2=df[df['Dates']=='1/1/1971 0:00']
df3=df2.append(df2.agg(['mean']))

But how can I take daily averages for the entire period?

fyec
  • 140
  • 19
  • 1
    Possible duplicate of [pandas dataframe groupby datetime month](https://stackoverflow.com/questions/24082784/pandas-dataframe-groupby-datetime-month) – hobbs Oct 22 '19 at 23:51
  • Yes, thank you, I solve it with the link. Anyway, I am going to give my solution, here. – fyec Oct 23 '19 at 00:29

1 Answers1

0

Here is the solution, thanks to pandas dataframe groupby datetime month. Here I used "D" instead of "M".

import pandas as pd  
inpcsvFile = 'C:/.../daily average - one day has multiple values.csv'
df = pd.read_csv(inpcsvFile)
df['Dates'] = df['Dates'].astype(str) #convert entire "Dates" Column to string 
df['Dates']=pd.to_datetime(df['Dates']) #convert entire "Dates" Column to datetime format this time 
df.index=df['Dates'] #replace index with entire "Dates" Column to work with groupby function
df3=df.groupby(pd.TimeGrouper(freq='D')).mean() #take daily average of multiple values
fyec
  • 140
  • 19