简体   繁体   中英

Figuring out the time format from datetime number

I have a dataset whose exact format or origin is unknown to me. I know that the time that the data was recorded is around September 2017, and the time column contains the following numbers:

[736887.61095486],
[736887.61096065],
...,
[736905.61505787],
[736905.61506366],

Any ideas how can I convert this to proper DateTime and use this column as my DataFrame index?

Now that we know that your numbers represent the number of days from January 0, 0000, we can use module datetime to reconstruct their calendar values:

import pandas as pd
from datetime import datetime, timedelta
data = ... # Your data
pd.Series(timedelta(d[0]) for d in data) + datetime(1,1,1)
#0   2018-07-13 14:39:46.499903
#1   2018-07-13 14:39:47.000162
#2   2018-07-31 14:45:40.999972
#3   2018-07-31 14:45:41.500221

Apparently, the date January 0, 0000 in Python corresponds to the year #1, month #1, and day #1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM