I'm working with a data frame that looks like this:
My goal is to group all of the power readings for a single day in the same row, by creating a column for each hour of the day. Also to group previous weather measurements (up to 48 measurements prior to current date) in the same row. So that the end df looks something like:
So far I've tried:
#col_dates is a list of all the dates in the dataframe, without duplicates
horpred=24
iterator = 1
for j in col_dates:
a=[]
for k in range(0,horpred):
#print(j,k)
a.append(df2.loc[(df['DATE']==j)&(df['HR']==k)] )
col_name = 'Y' + str(k)
#print(col_name)
df3.loc[:, col_name] = df2.loc[(df['DATE']==j)&(df['HR']==k)]
iterator += 1
But gotten the following error: ValueError: Wrong number of items passed 7, placement implies 1. Additionally, I'm aware that using a for loop might not be the fastest/best way to do this, so I'm wondering if there's any in-built attribute in pandas that might help