Pandas equivalent of MS Excel's concatenate

Viewed 25

I have a dataframe with mixed datatypes. I'm trying to find a way to create a column of concatenated values that I will later use as an indexed field.

My dataframe:

col1    col2    col3
str     num1    float1
str1    num3    float2

My desired output:

col1    col2    col3    combined_id
str     num1    float1  strnum1float1
str1    num3    float2  str1num3float2

What I've tried:

df['combined_id'] = df[['col1', 'col2', 'col3']].apply("".join, axis=1)

this gives an error of:

expected str instance, float found

Is there an efficient way to do this?

0 Answers
Related