This question is same to this posted earlier. I want to concatenate three columns instead of concatenating two columns:
Here is the combining two columns:
If you have even more columns you want to combine, using the Series method str.cat
might be handy:
df["combined"] = df["foo"].str.cat(df[["bar", "new"]].astype(str), sep="_")
Basically, you select the first column (if it is not already of type str
, you need to append .astype(str)
), to which you append the other columns (separated by an optional separator character).