原来是字符串格式,要改为datetime格式
from datetime import datetime
import pandas as pd
# 方法一:df['date'].astype('datetime64')
tran['date'] = tran['date'].astype('datetime64[ns]')
# 方法二:pd.to_datetime
tran['date'] = pd.to_datetime(tran['date']) # date转为时间格式
# 方法三:datetime.strptime(x,'%Y-%m-%d') 缺点:耗时太长
tran['date'] = tran['date'].apply(lambda x: datetime.strptime(x,'%Y-%m-%d'))