Pandas-21.时间
- now
print(pd.datetime.now())
# 2019-04-03 23:06:58.992842
- Timestamp
print(pd.Timestamp("2020-1-1"))
# 2020-01-01 00:00:00
print(pd.Timestamp(1588686880, unit='s'))
# 2020-05-05 13:54:40
- date_range
print(pd.date_range("12:00", "14:30",freq="30min").time)
'''
[datetime.time(12, 0) datetime.time(12, 30) datetime.time(13, 0)
datetime.time(13, 30) datetime.time(14, 0) datetime.time(14, 30)]
'''
- 转换为时间戳
类似日期,时间的对象,用
to_datetime
函数尝试转换,Series返回Series,List转换为DatetimeIndex:
print(pd.to_datetime(pd.Series(['Jul 31, 2009','2019-10-10', None])))
'''
0 2009-07-31
1 2019-10-10
2 NaT
dtype: datetime64[ns]
'''
print(pd.to_datetime(['2009/11/23', '2019.12.31', None]))
'''
DatetimeIndex(['2009-11-23', '2019-12-31', 'NaT'], dtype='datetime64[ns]', freq=None)
'''
NaT类似NaN