作为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
像这样的怎么样?
如果有
None
对象浮动,也可以处理它。例如:近英语:
使用
filter
:你可以一行一行地做,但我想分开比较清楚。
相关问题 更多 >
编程相关推荐