pandas 日期时间格式VS Google表格日期格式 [英] pandas date-time format VS google sheets date format

查看:61
本文介绍了 pandas 日期时间格式VS Google表格日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据集中有一列如下所示:

I have a column in my dataset that looks like this:

date  
41245.0  
41701.0  
36361.0

我需要将其转换为日期格式.当我使用以下命令在Python中尝试时:

I need to convert it into a date-format. When I try it in Python using this:

df = pd.to_datetime(df['date'])

我的结果是这样的:

1   1970-01-01 00:00:00.000041701
4   1970-01-01 00:00:00.000042226
5   1970-01-01 00:00:00.000039031

这些年似乎很奇怪.但是,当我在Google云端硬盘/表格上打开我的数据集(作为Excel工作表)时,请选择该列,然后使用日期"或日期时间"格式,结果却大不相同.

These years seem quite odd. However, when I open the my dataset(as an excel sheet) on Google Drive/Sheets, select the column, and format it using the "date" or "date-time" format, the results are quite different.

12/2/2012
3/3/2014
7/20/1999

我的结果应该是这样的.但是,目前我正在获得怪异的价值观.同样,Microsoft Excel上的结果也略有不同.为什么日期不同?我在做什么错了?

My results should be something like this. However, currently I am getting weird values. Similarly, the results on Microsoft Excel were also slightly different. Why are the dates different? What am I doing wrong?

推荐答案

那是几天,但原点是1900-01-01,而不是默认的1970-01-01

That is days but the origin is 1900-01-01 not the default 1970-01-01

pd.to_datetime(df.date,unit='d',origin='1900-01-01')
Out[205]: 
0   2012-12-04
1   2014-03-05
2   1999-07-22
Name: date, dtype: datetime64[ns]

这篇关于 pandas 日期时间格式VS Google表格日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆