【发布时间】:2017-05-25 03:11:08
【问题描述】:
假设我有一个非常简单的数据框:
>>> a
Out[158]:
monthE yearE dayE
0 10 2014 15
1 2 2012 15
2 2 2014 15
3 12 2015 15
4 2 2012 15
假设我想使用三列整数创建具有与每一行相关的日期的列。 当我有简单的数字时,这样做就足够了:
>>> datetime.date(1983,11,8)
Out[159]: datetime.date(1983, 11, 8)
如果我必须创建一列日期(理论上是一个非常基本的请求),则改为:
a.apply(lambda x: datetime.date(x['yearE'],x['monthE'],x['dayE']))
我收到以下错误:
KeyError: ('yearE', u'occurred at index monthE')
【问题讨论】:
标签: python-2.7 datetime pandas dataframe