将datetime.datetime对象转换为Python中的epoch之后的天数 [英] Convert datetime.datetime object to days since epoch in Python
本文介绍了将datetime.datetime对象转换为Python中的epoch之后的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 pandas.Series
对象,可能如下所示:
I've got a pandas.Series
object that might look like this:
import pandas as pd
myVar = pd.Series(["VLADIVOSTOK 690090", "MAHE", NaN, NaN, "VLADIVOSTOK 690090", "2000-07-01 00:00:00"])
myVar [5]
被解析作为 datetime.datetime
对象,当数据通过 pandas
读入Python时。我假设将这个值转换为自纪元(36708)以来的天数并不困难。我只是Python的新手,不知道该怎么做。感谢提前!
myVar[5]
is parsed as a datetime.datetime
object when the data is read into Python via pandas
. I'm assuming that converting this value to the number of days since epoch (36708) isn't difficult at all. I'm just new to Python and don't know how to do it. Thanks in advance!
推荐答案
myVar = pd.Series(["VLADIVOSTOK 690090", "MAHE", "NaN", "NaN", "VLADIVOSTOK 690090", "2000-07-01 00:00:00"])
myVar[5] = pd.to_datetime(myVar[5]) - pd.datetime(1970,1,1)
print(myVar)
0 VLADIVOSTOK 690090
1 MAHE
2 NaN
3 NaN
4 VLADIVOSTOK 690090
5 11139 days 00:00:00
dtype: object
这篇关于将datetime.datetime对象转换为Python中的epoch之后的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文