my max and min date are 2023-04-21 00:00:00 and 2023-04-01 00:00:00, a three weeks range beginning at Saturday.
`
df = pd.read_csv(file, usecols=['distance', 'class_index',
' date'])
df['date'] = pd.to_datetime(df['date'])
max_date = df['date'].max()
min_date = df['date'].min()
print(f"{max_date}")
print(f"{min_date}")
df.set_index('date', inplace=True)
weekly_avg = df.groupby('class_index').resample('W',
closed='right',
loffset=pd.DateOffset(days=-1)).mean()`
and my result is:
distance class_index
class_index date
0.0 2023-04-01 16.472320 0.0
2023-04-08 18.160144 0.0
2023-04-15 19.178941 0.0
2023-04-22 20.124844 0.0
1.0 2023-04-01 9.559542 1.0
2023-04-08 10.213785 1.0
2023-04-15 10.849616 1.0
2023-04-22 11.068927 1.0
why 2023-4-22 is there?
my expectation1 is:
distance class_index
class_index date
0.0 2023-04-01 16.472320 0.0
2023-04-08 18.160144 0.0
2023-04-15 19.178941 0.0
1.0 2023-04-01 9.559542 1.0
2023-04-08 10.213785 1.0
2023-04-15 10.849616 1.0