问题描述
我有一个这样的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 DATE
和MEETING 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
这篇关于将日期列和时间列合并为日期时间列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!