0

What is the easiest way to get this Date and Time in two separate columns into a Pandas to_datetime (with the correct formatting) and set it as the index?

Date        Time    Open    High    Low     Close   Volume  
20180316    1935    178.15  178.24  178.15  178.24  5000.0
20180316    1937    178.04  178.04  178.04  178.04  80.0
20180316    1939    178.06  178.06  178.06  178.06  300.0
20180316    1946    178.01  178.01  178.01  178.01  50.0

Here are the dtypes for reference

Date              int64
Time              int64
Open            float64
High            float64
Low             float64
Close           float64
Volume          float64
sslack88
  • 1,403
  • 3
  • 10
  • 15

1 Answers1

0

Convert to string , then add together pass the correct format in to_datetime

df.index=pd.to_datetime(df.Date.astype(str)+df.Time.astype(str),format='%Y%m%d%H%M')
Out[1142]: 
0   2018-03-16 19:35:00
1   2018-03-16 19:37:00
2   2018-03-16 19:39:00
3   2018-03-16 19:46:00
dtype: datetime64[ns]
BENY
  • 317,841
  • 20
  • 164
  • 234