Skip to content

Instantly share code, notes, and snippets.

@kperry2215
Created July 30, 2019 22:19
Show Gist options
  • Save kperry2215/4549bbafa0e5488e85639c9714c2498a to your computer and use it in GitHub Desktop.
Save kperry2215/4549bbafa0e5488e85639c9714c2498a to your computer and use it in GitHub Desktop.
#Pull the day of month for each reading
electricity_demand_df['Day_Of_Month']=electricity_demand_df['Date_Time'].dt.day
#Pull the month of the year
electricity_demand_df['Month']=electricity_demand_df['Date_Time'].dt.month.apply(lambda x: calendar.month_abbr[x])
#Pull the year
electricity_demand_df['Year']=electricity_demand_df['Date_Time'].dt.year
#Calculate the hour with max demand for each date in the data set
electricity_demand_df['Peak_Demand_Hour_MWh_For_Day']=electricity_demand_df.groupby(['Day_Of_Month',
'Month',
'Year'], sort=False)['Electricity_Demand_MWh'].transform('max')
#Subset time series to only include peak hourly data
peak_demand_hour_df=electricity_demand_df[electricity_demand_df[
'Electricity_Demand_MWh']==electricity_demand_df['Peak_Demand_Hour_MWh_For_Day']]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment