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

后端 未结 11 1725
梦谈多话
梦谈多话 2020-12-02 14:25

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:

         


        
11条回答
  •  青春惊慌失措
    2020-12-02 14:50

    df = DataFrame({'foo':['a','b','c'], 'bar':[1, 2, 3], 'new':['apple', 'banana', 'pear']})
    
    df['combined'] = df['foo'].astype(str)+'_'+df['bar'].astype(str)
    

    If you concatenate with string('_') please you convert the column to string which you want and after you can concatenate the dataframe.

提交回复
热议问题