Convert between pandas DatetimeIndex to Python datetime:
dt_df = df_w.index.to_frame()
dt_series = df_w.index.to_series()
print(dt_df.dtypes) # --> Date datetime64[ns]
print(dt_series.dtypes) # datetime64[ns]
for x in dt_df["Date"]:
assert isinstance(x, pd.Timestamp)
d = x.to_pydatetime()
cw = d.isocalendar().week
print(f"{d} - cw{cw}")
for x in dt_series:
assert isinstance(x, pd.Timestamp)
d = x.to_pydatetime()
cw = d.isocalendar().week
print(f"{d} - cw{cw}")