Consider following dataframe and the need to merge A and B in an expanded list:
df = pd.DataFrame([[['abc', 'def'], 'zzz']] * 3, columns=['A', 'B'])
A B
0 [abc, def] zzz
1 [abc, def] zzz
2 [abc, def] zzz
add (or +) won't work as-is because B is a string so I am doing so:
df.A = df.A.add(df.B.apply(lambda x: [x]))
df.drop(['B'], axis=1)
A
0 [abc, def, zzz]
1 [abc, def, zzz]
2 [abc, def, zzz]
but I was wondering if there is a better (performing) way.
I could not find a one-liner built-in method to add values of a Series to an existing list-like Series. It seems you always must apply() to a list first.