我有一个dataframe
,其中日期列的格式是format='%Y-W%W-%w'
。我正在使用pd.to_datetime(urldict[key]['date']+'-1', format='%Y-W%W-%w')
将2018-W01
等转换为实际日期,但由于闰年的原因,2020/2021年的数据似乎发生了错误的移动
随后,它为01-04-2021
创建两个条目,第一个条目是2020-W53
。返回的数据也未对齐
我不确定如何解决这个问题,因为我假设datetime库会解决这个问题
转换前:
date region total
2020-W51 africa 1
2020-W52 africa 2
2020-W53 africa 3
2021-W01 africa 4
转换后:
date region total
12/21/2020 africa 1
12/28/2020 africa 2
1/4/2021 africa 3
1/4/2021 africa 4
似乎您需要ISO 8601年/周/工作日,因此正确的格式化指令应该是
'%G-W%V-%u'
(请参见the docs,该部分的末尾)。为了那看起来像
相关:Python - Get date from day of week, year, and week number
相关问题 更多 >
编程相关推荐