Python dateTtimeZ到日期、时间

Python dateTtimeZ到日期、时间,python,pandas,Python,Pandas,“我的数据帧”包含一列,其中包含此(示例)格式的时间戳值: 2019-12-31T23:20:10.000Z 当前,此列的类型为对象 我想: (1)将其转换为datetime类型 (2)将此列拆分为两列:日期和时间,如本例所示: 2019-12-31 23:20:10 (3)只记录2019年12月15日之前发生的观察结果。使用pd.to\u datetime df['timestamp'] = pd.to_datetime(df['timestamp']) 约会 df['date'] = df

“我的数据帧”包含一列,其中包含此(示例)格式的时间戳值:
2019-12-31T23:20:10.000Z

当前,此列的类型为
对象

我想:

(1)将其转换为
datetime
类型

(2)将此列拆分为两列:
日期
时间
,如本例所示:

2019-12-31

23:20:10


(3)只记录2019年12月15日之前发生的观察结果。

使用
pd.to\u datetime

df['timestamp'] = pd.to_datetime(df['timestamp'])
约会

df['date'] = df.timestamp.dt.date
暂时

df['date'] = df.timestamp.dt.time
按时间戳过滤

condition = (df.timestamp < '2019-12-15')
sample_df = df[condition].sample(n=2)
def memoize_dt(s):
    dates = {date:datetime.datetime.strptime(date,'%b-%d-%Y') for date in s.unique()}
    return s.map(dates)

这是最快的矢量化方法。对于如此大的数据集,如果需要,请查看并行或分布式计算@qwerty