【发布时间】:2019-04-15 17:10:01
【问题描述】:
我有一个数据框,其中包含单独的年份和月份列,例如:
Year Month
2001 1
2001 2
2001 3
.
.
2010 1
2010 2
.
使用pd.to_datetime(df[['year', 'month']]) 转换为pd.datetime 需要几天才能匹配格式,所以我收到错误:
ValueError: to assemble mappings requires at least that [year, month, day] be specified: [day] is missing
我觉得我可以用 Day = 1 重复填充一个新列,但我想避免这种情况,因为我只想按年创建一个时间序列。
有没有办法将年月映射到日期以正确绘制图表?
【问题讨论】:
标签: python python-3.x pandas date dataframe