I have a column in my dataset that looks like this:
date
41245.0
41701.0
36361.0
I need to convert it into a date-format. When I try it in Python using this:
df = pd.to_datetime(df['date'])
My results are like this:
1 1970-01-01 00:00:00.000041701
4 1970-01-01 00:00:00.000042226
5 1970-01-01 00:00:00.000039031
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
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?
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]
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加