I have a huge dataset of the temperature of each hour on a day for 50+ cities. I want to get dataframe of max,min, and average tempearture date-wise for each city. For eg Dataset contains
City Date Time Temperature
New York 11/10/2020 10:00 20
New York 11/10/2020 11:00 20
New York 11/10/2020 12:00 21
New York 11/10/2020 13:00 22
New York 11/10/2020 14:00 24
New York 11/10/2020 15:00 25
New York 11/10/2020 16:00 26
New York 11/10/2020 17:00 27
New York 11/10/2020 18:00 26
New York 11/10/2020 19:00 24
New York 11/10/2020 20:00 25
I want dataframe for each city that contains Max, min, and average temperature for every day (like city1_df, city2_df) etc.. I have tried groupby function inside groupby, but does not know how to iterate the process with different variable names. How can I automate this process through various cities?
What I have tried:
cities=df.groupby('City')
city1=cities.get_group('New York')
city1_max=city1.groupby('Date').max()
city1_min=city1.groupby('Date').min()
city1_avg=city1.groupby('Date').mean()
city1_max=city1_max.drop(columns=['City','Time'])
city1_min=city1_min.drop(columns=['City','Time'])
city1_max=city1_max.rename(columns={'Temperature':'Max Temp'})
city1_min=city1_min.rename(columns={'Temperature':'Min Temp'})
city1_avg=city1_avg.rename(columns={'Temperature':'Avg Temp'})
city1_df=pd.concat(['city1_max','city1_min','city1_avg'], axis=1)