Pandas时间序列:to_datetime

from datetime import datetime

to_datetime通常用于处理成组日期

datestrs = ['3/7/2018','4/7/2018']
pd.to_datetime(datestrs)
DatetimeIndex(['2018-03-07', '2018-04-07'], dtype='datetime64[ns]', freq=None)

to_datetime还可以处理空值

idx = pd.to_datetime(datestrs+[None])
print(idx)
print(idx[2]) # NaT表示Not a Time
DatetimeIndex(['2018-03-07', '2018-04-07', 'NaT'], dtype='datetime64[ns]', freq=None)
NaT
pd.isnull(idx)
array([False, False,  True], dtype=bool)

你可能感兴趣的:(Pandas)