My data set contains multiple columns of sales-related data. I have ORDEREDDATE
and TIMESTAMP
in the DataFrame. I want to replace the column with ORDEREDTIME
in the dataset.
ORDEREDDATE TIMESTAMP
2018-05-13 21:54:45
2017-08-24 5:44:25
2018-06-01 6:58:15
my expected output is
ORDEREDTIME
2018-05-13 21:54:45
2017-08-24 05:44:25
2018-06-01 06:58:15
in a single column.
IIUC
pd.to_datetime(df[['ORDEREDDATE','TIMESTAMP']].astype(str).agg(' '.join,1))
Out[19]:
0 2018-05-13 21:54:45
1 2017-08-24 05:44:25
2 2018-06-01 06:58:15
dtype: datetime64[ns]
df['ORDEREDTIME'] = pd.to_datetime(df.astype(str).agg(' '.join,1))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.