python快速将一个dataframe的某一列转为时间戳

加上库

from datetime import datetime
def time2stamp(cmnttime):   #转时间戳函数
    cmnttime=datetime.strptime(cmnttime,'%Y-%m-%d %H:%M:%S')
    stamp=int(datetime.timestamp(cmnttime))
    return stamp


 

直接用apply调用函数

df_train['CREATE_DATE']=df_train['CREATE_DATE'].apply(time2stamp)

猜你喜欢

转载自blog.csdn.net/yigeng3663/article/details/83270069
今日推荐