Basically, I have dataframe like this:
c1 c2
0 a x
1 b NaN
and I want to have column c like this:
c1 c2 c
0 a x [a, x]
1 b NaN [b]
Here is my solution:
import pandas as pd
import numpy as np
df = pd.DataFrame({'c1': ['a', 'b'], 'c2': ['x', np.nan]})
df['c'] = df[['c1', 'c2']].values.tolist()
df['c'] = df['c'].apply(lambda x: [i for i in x if i is not np.nan])
but I suppose something shorter, simpler and more pandonic exists. Could you help me with one-liner for this?