I have tried to resample a dataframe from minutes to daily. For this I used the following lines:
df_1d = df.resample('D')['Value'].sum().asfreq(freq='D').reset_index()
df_1d.set_index(pd.DatetimeIndex(df_1d['DateTime']), inplace=True)
df_1d = df_1d.drop('DateTime', axis=1)
df_1d.drop(df_1d.loc[df_1d['Value']=='0.00'].index, inplace=True)
df_1d.dropna(subset='Value', inplace=True)
My DataFrame df has two columns one called 'DateTime', containing timestamps in format %Y-%m-%d %H:%M:%S. The other contains values like 0.01, 0.05 and 0.25.
The Code written so far should resample the Values, calculate the sum for each day and reset the index afterwards.
Then I want to set the Index again as a DatetimeIndex and drop off the now unsused column DateTime as there is now an index with this name.
Now I want to see only those rows, where Value is not 0. And at the end drop off all NaN-Values found in column Value.
This doesn't work as it should. At least the resampled dataframe looks like this:
Value
DateTime
2021-09-06 0.010.050.25
It seems like my code just merge the rows for each interval instead of calculating a sum.
I also tried to use a simplier code.
df_1d = df.resample('D').sum(min_count=1).asfreq(freq='D').dropna()
But with this I got the same result.
Does anyone knows where I made a mistake?
Thanks in advance.
EDIT:
My desired output should look like this:
Value
DateTime
2021-09-06 0.31