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.<
This is one of the few things that a for loop would be appropriate for in pandas
for
col_names = rdf.columns.tolist() rdf["NEW"] = "" for col in col_names: rdf.loc[rdf[col] == 1, "NEW"] = rdf.loc[rdf[col] == 1, "NEW"] + ("," + col) rdf["NEW"] = rdf["NEW"].str.strip(",")