Let's say I have a dataframe
like this:
a b c d
0 S t f nan
1 S t t nan
2 S f nan nan
3 Q t nan nan
I want to combine the last 3 columns into a single column, as an array, but exclude the nan values, so I end up getting something like the following:
a b c d e
0 S t f nan [t, f]
1 S t t nan [t, f]
2 S f nan nan [f]
3 Q t nan nan [t]
The closest I was able to get was using iloc
but I'm unable to apply a conditional to it properly:
df['e'] = df.iloc[:, 1:].values.tolist()
The above results in the arrays having all the column values, including nans.