Search code examples
pythondatetimepandasdata-analysis

Combine date column and time column into datetime column


I have a Pandas dataframe like this; (obtained by parsing an excel file)

|     |     COMPANY NAME           | MEETING DATE        | MEETING TIME|
-----------------------------------------------------------------------|
|YKSGR|    YAPI KREDİ SİGORTA A.Ş. | 2013-12-16 00:00:00 |14:00:00     |
|TRCAS|    TURCAS PETROL A.Ş.      | 2013-12-12 00:00:00 |13:30:00     |

Column MEETING DATE is a timestamp with a representation like Timestamp('2013-12-20 00:00:00', tz=None) and MEETING TIME is a datetime.time object with a representation like datetime.time(14, 0)

I want to combine MEETING DATE and MEETING TIME into one column. datetime.combine seems to do what I want, however, I need to apply this function column-wise somehow. How can I achieve this?


Solution

  • You can use apply method, and apply combine like this:

    >>> df.apply(lambda x: combine(x['MEETING DATE'], x['MEETING TIME']), axis=1)
    0   2013-12-16 14:00:00
    1   2013-12-12 13:00:00