I have a data frame with over 180 columns that I need to sum over a time interval. The below resample code works fine when I enter the column names directly but not in a loop. Because of the large number of columns, I cannot write each of the column names separately.
The code that works:
df_agg = df.resample('1D', on='Date').agg({'col1' : 'sum', 'col2' :'sum'})
The code that does not work:
for x in range(180):
df_agg = df.iloc[:, 0:x].resample('1D', on='Date').sum()
I get the following error: 'The grouper name Date is not found'
The date column is in DateTime. I tried setting the Date column as the index, but then it says that the resample function only works with DateTime. What should be done now? Any help would be highly appreciated.