【发布时间】:2012-08-19 22:06:01
【问题描述】:
作为this post 的后续行动,我想根据它们的索引连接一些列,但我遇到了一些问题。在此示例中,我收到与 map 函数相关的属性错误。解决此错误的帮助以及对列进行等效连接的代码将不胜感激。
#data
df = DataFrame({'A':['a','b','c'], 'B':['d','e','f'], 'C':['concat','me','yo'], 'D':['me','too','tambien']})
#row function to concat rows with index greater than 2
def cnc(row):
temp = []
for x in range(2,(len(row))):
if row[x] != None:
temp.append(row[x])
return map(concat, temp)
#apply function per row
new = df.apply(cnc,axis=1)
#Expected Output
new
concat me
me too
yo tambien
谢谢, 扎克cp
【问题讨论】:
-
请发布您收到的错误以及您的预期输出。
-
@BrenBarn。完成,谢谢。