我有一个带有日期列的csv,日期列为MM/DD/YY,但是我想将年份从00,02,03改为1900,1902,1903,这样它们就被列为MM/DD/YYYY
这就是我的工作原理:
df2['Date'] = df2['Date'].str.replace(r'00', '1900')
但我每年都要这样做直到68岁(也就是重复68次)。我不知道如何创建一个循环,以便在该范围内每年执行上述代码。我试过这个:
ogyear=00
newyear=1900
while ogyear <= 68:
df2['date']=df2['Date'].str.replace(r'ogyear','newyear')
ogyear += 1
newyear += 1
但这将返回一个空数据集。还有别的办法吗?你知道吗
我不能使用datetime,因为它假定02引用的是2002而不是1902,当我试图将其编辑为日期时,python会显示一条错误消息,指出日期是不可变的,必须在原始数据集中更改。因为这个原因,我需要保持字符串的日期。我还附上了csv在这里的情况下,这是有帮助的。你知道吗
我会这样做:
我会这样做:
相关问题 更多 >
编程相关推荐