1

I have a dataframe which looks like:

    d           t 
Var         
1   20160719    08:26:00
2   20160719    08:54:00

I am intending to convert the two columns d and t to a timestamp using something along

pd.to_datetime(df)

Somehow, I don't succeed doing this. Combining the date in one column and the time in the other column doesn't seem to work. I can feed the individual columns\series into pd.to_datetime, which works fine. But then I miss either date or time. Any advice or example would be super useful. Many thanks!

Steffen

Steffen
  • 79
  • 11

1 Answers1

2

This is the easiest way to get what you need. You can just add together the 2 columns with a space so you can apply .to_datetime(). I created an other column df['timestamp'] for this answer but you can just do whatever you need to do.

df['timestamp'] = pd.to_datetime(df['d'] + ' ' + df['t'])

df

Output:

    d           t           timestamp
0   20160719    08:26:00    2016-07-19 08:26:00
1   20160719    08:54:00    2016-07-19 08:54:00
Joe T. Boka
  • 6,554
  • 6
  • 29
  • 48