from datetime import datetime
start_time=datetime(year=2019,month=2,day=1,hour=4,minute=0,second=0)
end_time=datetime(year=2019,month=2,day=1,hour=4,minute=5,second=0)
1. 两列时间相减
方法一:
pd.DataFrame((pd.to_datetime(df['finished_time']) -
pd.to_datetime(df['begun_time'])).apply(lambda x: int(x/np.timedelta64(1,'m'))))
2. 某列日期数据进行拆分
df['start_day']=pd.to_datetime(df['begun_time']).dt.day
df['start_hour']=pd.to_datetime(df['begun_time']).dt.hour
df['start_minute']=pd.to_datetime(df['begun_time']).dt.minute
leave['date'] = pd.to_datetime(leave['register_time'],format='%Y-%m-%d %H:%M:%S').dt.date
pd.to_datetime(某日期列,format=格式)
:pandas.core.series.Series
.dt.day
是其属性