作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在以正确格式转换我的日期时遇到问题。
我有一个看起来像这样的列:20130525,存储为 int64
。
我正在尝试将其设置为日期,但遇到了问题。
我写了一个看起来像这样的函数:
def reformat_dates(df):
df['column'] = pd.to_datetime(df['column'], format = "%Y-%m-%d")
return df
但是当我执行该函数时,我最终得到这样的一列:
1970-01-01 00:00:00.020130525
是不是我的函数有什么问题导致它默认为这种方式?我希望格式为
2013-05-25
最佳答案
我认为您正在转换的列是 UNIX 时间戳格式。
您应该使用 unit='s'
。
def reformat_dates(df):
df['column'] = pd.to_datetime(df['column'], unit='s')
return df
关于python - Pandas 的日期时间默认为 1970,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51587468/
我是一名优秀的程序员,十分优秀!