As a follow up to this post, I would like to concatenate a number of columns based on their index but I am encountering some problems. In this example I get an Attribute error related to the map function. Help around this error would be appreciated as would code that does the equivalent concatenation of columns.
#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
thanks, zach cp