-3

I am very new at coding and need some guidance. I am attempting to forecast the timing of the daily peak load (hour in which the peak load occurs). Here is a snapshot of the first day in 2002 data: During the first hour on January 1, 2002, the average, median, maximum, and minimum temperatures were recorded as 43, 43, 60, and 31 degrees Fahrenheit, respectively. In this same hour, a total of 1,384,494 MWh (megawatt-hours) of electricity load was consumed.

Essentially trying to find the maximum values of load per 24 hours and then its corresponding time.So far I have this but it not working.
max_Load = df3.groupby(df3.index // 24)['Load'].idxmax()
max_df = df3.loc[max_Load.index * 24].reset_index(drop=True)
max_df['max_Load'] = max_Load.valuesmax_df

Included in the picture is what it outputs: Max load is way off

  • Welcome to SO, please [edit] your question to provide more details. In particular you should provide a clear [reproducible example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) of input/output – mozway Apr 27 '23 at 08:09
  • You must add more details and code you tried so far – gtomer Apr 27 '23 at 08:32

1 Answers1

0
max_Load = df3.groupby(df3.index // 24).idxmax()["Load"]
max_df = df3.loc[max_Load].reset_index(drop=True)

Basically df3.groupby(df3.index // 24).idxmax() gives you a data frame where the index is the possible values for df3.index // 24 and the columns are the original columns from your df3. The values are the indices of the maximum value for that column for each value of df.index // 24. Just take the "Load" column of this to get the indices of df3 where "Load" is maximal from each value of df3.index // 24.

KangarooChief
  • 381
  • 3
  • 14