Combine two or more columns into a new column by row condition

后端 未结 3 1953
既然无缘
既然无缘 2021-01-21 18:52

I would like to combine two or more columns into a new columns, based on the row condition ( which is 1, an integer ) the new columns should be a column contains joined string.<

3条回答
  •  醉酒成梦
    2021-01-21 19:27

    This could do the job

    rdf['New'] = rdf.replace(1, pd.Series(rdf.columns+',', rdf.columns)).\
                                               replace(0, '').sum(axis = 1).\
                                               str.strip(',')
    
    

提交回复
热议问题