【发布时间】:2021-12-03 18:28:29
【问题描述】:
我有一列以整数表示月份,还有一个以白天格式存储当前日期的变量。我需要创建一个更新月份的列:
df_final["Date"] = current_day.replace(month=df_final["Month"])
但我收到以下错误:
/venv/lib/python3.8/site-packages/pandas/core/series.py", line 185, in wrapper
raise TypeError(f"cannot convert the series to {converter}")
TypeError: cannot convert the series to <class 'int'>
我不知道为什么,有什么建议吗?
【问题讨论】:
-
我看到的大部分文档都在使用 .replace(['old value'],'new value'),没有看到任何单个参数重载,但我会从它开始。您还使用列更新月份变量吗?编辑:抱歉应该添加link
-
尝试
df_final['Date'] + pd.DateOffset(Month=df_final['Month'])用于日期时间操作数,您需要使用适当的函数.replace用于字符串。
标签: python pandas datetime typeerror