我有一个数据框df
,其值为:
df.iloc[1:4, 7:9]
Year Month
38 2020 4
65 2021 4
92 2022 4
我正在尝试创建一个新MonthIdx
列:
df['MonthIdx'] = pd.to_timedelta(df['Year'], unit='Y') + pd.to_timedelta(df['Month'], unit='M') + pd.to_timedelta(1, unit='D')
但我得到了错误:
ValueError: Units 'M' and 'Y' are no longer supported, as they do not represent unambiguous timedelta values durations.
以下是所需的输出:
df['MonthIdx']
MonthIdx
38 2020/04/01
65 2021/04/01
92 2022/04/01