I would like to assign a binary value (1 or 0) whether a column contains not empty/empty lists.
For example:
Country Test
Germany []
Italy ['pizza']
United Kingdom ['queen', 'king','big']
France ['Eiffel']
Spain []
...
What I would expect is something like this:
Country Test Binary
Germany [] 0
Italy ['pizza'] 1
United Kingdom ['queen', 'king','big'] 1
France ['Eiffel'] 1
Spain [] 0
...
I do not know how to use np.where or another to get these results.
I think to check if a column contains an empty list I should do something like this: df[df['Test'] != '[]']
df['Binary'] = (df['Test'] != []).astype(int)df['Binary'] = (df['Test'].neq([])).astype(int)thendf['Test'].astype(bool).astype(int)df['Binary'] = (df['Test'].str.len() != 0).astype(int)worked for me.