将日期列和时间列合并为日期时间列 [英] Combine date column and time column into datetime column

查看:137
本文介绍了将日期列和时间列合并为日期时间列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的Pandas数据框; (通过解析excel文件获得)

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     |

MEETING DATE是带有Timestamp('2013-12-20 00:00:00', tz=None)表示形式的时间戳,而MEETING TIME是带有datetime.time(14, 0)

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)

我想将MEETING DATEMEETING TIME合并为一列. datetime.combine 似乎可以满足我的要求,但是,我需要申请此函数以某种方式逐列显示.我该如何实现?

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?

推荐答案

您可以使用apply方法,并应用如下组合:

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

这篇关于将日期列和时间列合并为日期时间列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆