skip to content
barorin&

pandasで全ての列をカンマで区切って結合した新しい列を作成する方法

/ 1 min read

Table of Contents

はじめに

簡単ですが、これで解決するまで結構調べてしまいました…。
こういう列を

  • df
A B
a b
c d

こうします。

  • df_new
A B new_col
a b a,b
c d c,d

方法

df_new['new\_col'] = df.apply(','.join, axis=1)