I have a problem trying to access values in a custom dataframe: My original dataframe is:
print(df)
Data1 Data2 Data3
IMX01 2022-08-12 22:00:00 400.00 500.00 600.00
IMX01 2022-08-15 22:00:00 400.00 500.00 600.00
IMX01 2022-08-30 22:00:00 400.00 500.00 600.00
IMX01 2022-09-12 22:00:00 400.00 500.00 600.00
IMX01 2022-09-15 22:00:00 400.00 500.00 600.00
IMX01 2022-09-30 22:00:00 400.00 500.00 600.00
RTX01 2022-08-12 22:00:00 400.00 500.00 600.00
RTX01 2022-08-15 22:00:00 400.00 500.00 600.00
RTX01 2022-08-30 22:00:00 400.00 500.00 600.00
RTX01 2022-09-12 22:00:00 400.00 500.00 600.00
RTX01 2022-09-15 22:00:00 400.00 500.00 600.00
RTX01 2022-09-30 22:00:00 400.00 500.00 600.00
... ... ... ... ...
And the custom made is filtered and grouped by the first index, and resampled by frequency (monthly) by second index (datetime).
df_custom = df[df.index.get_level_values(0).isin(["IMX01"])].sort_index(level=1).groupby(level=0).resample("M", level=1).sum()
Data1 Data2 Data3
IMX01 2022-08-31 1200.00 1500.00 1800.00
IMX01 2022-09-30 1200.00 1500.00 1800.00
My problem is when i tried using df_custom.loc[[("IMX01", "2022-08-31")]]
it didn't work, and when i tried on the original dataframe it worked df.loc[[("IMX01", "2022-08-12 22:00:00")]]
.
It says:
KeyError: "None of [MultiIndex([("IMX01", "2022-08-31")],\n )] are in the [index]"
I think the problem is when i resample a time series to another frequency, but i don't have any idea how to fix it. Any suggestions?