close

How to concatenate multiple column values into a single column in Pandas dataframe

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to concatenate multiple column values into a single column in Pandas dataframe in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

How to concatenate multiple column values into a single column in Pandas dataframe?

  1. How to concatenate multiple column values into a single column in Pandas dataframe?

    Another solution using DataFrame.apply(), with slightly less typing and more scalable when you want to join more columns:

  2. concatenate multiple column values into a single column in Pandas dataframe

    Another solution using DataFrame.apply(), with slightly less typing and more scalable when you want to join more columns:

Method 1

Another solution using DataFrame.apply(), with slightly less typing and more scalable when you want to join more columns:

cols = ['foo', 'bar', 'new']
df['combined'] = df[cols].apply(lambda row: '_'.join(row.values.astype(str)), axis=1)

Method 2

you can simply do:

In[17]:df['combined']=df['bar'].astype(str)+'_'+df['foo']+'_'+df['new']

In[17]:df
Out[18]: 
   bar foo     new    combined
0    1   a   apple   1_a_apple
1    2   b  banana  2_b_banana
2    3   c    pear    3_c_pear

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read