I am trying to concat all my columns into a new column. The concatenated values should be stored in a list.
My dataframe:
df = pd.DataFrame({'A': ['1', '2', nan],
'B': [nan, '5', nan],
'C': ['7', nan, '9']})
desired output:
df:
A B C concat_col
1 nan 7 [1,7]
2 5 nan [2,5]
nan nan 9 [9]
What i tried:
df['concat'] = pd.Series(df.fillna('').values.tolist()).str.join(',')
Output i got:
A B C concat_col
1 nan 7 1,,7
2 5 nan 2,5,,
nan nan 9 ,,9