简体   繁体   English

从日期时间数字中找出时间格式

[英]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: 我知道记录数据的时间是2017年9月左右,并且time列包含以下数字:

[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? 任何想法如何将其转换为正确的DateTime并将此列用作我的DataFrame索引?

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: 现在我们知道您的数字代表从0000年1月0日开始的天数,我们可以使用datetime模块重构其日历值:

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. 显然,Python中的日期January 0,0000对应于#1年,#1月和#1天。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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