Equivalent of Paste R to Python

后端 未结 8 708
忘掉有多难
忘掉有多难 2021-02-01 14:32

I am a new python afficionado. For R users, there is one function : paste that helps to concatenate two or more variables in a dataframe. It\'s very useful. For example Suppose

8条回答
  •  暖寄归人
    2021-02-01 15:15

    If you want to just paste two string columns together, you can simplify @shouldsee's answer because you don't need to create the function. E.g., in my case:

    df['newcol'] = df['id_part_one'].str.cat(df['id_part_two'], sep='_')
    

    It might be required for both Series to be of dtype object in order to this (I haven't verified).

提交回复
热议问题