我想将日期从 sas 14487 转换为 1999-08-31。
如何将当前结果“1999-08-31 00:00:00”转换为“1999-08-31”? 我试过 ser.normalize()。但这没有帮助。
ser = pd.to_timedelta(14487, unit='D') + pd.Timestamp('1960-1-1')
ser.normalize()
产量
Timestamp('1999-08-31 00:00:00')
最佳答案
normalize
只是将时间重置为午夜(根据 the docs )。
您可以使用 strftime
(参见文档 here)。另外,here是您可以使用的格式说明符的列表。
ser = pd.to_timedelta(14487, unit='D') + pd.Timestamp('1960-1-1')
ser.strftime('%Y-%m-%d')
输出
'1999-08-31'
关于python - 从时间戳中删除小时、分钟、秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38709670/