I have a pandas DataFrame where one column contains lists and would like to select the rows where the lists are not empty.
Example data:
df = pd.DataFrame({'letter': ["a", "b", "c", "d", "e"],
'my_list':[[0,1,2],[1,2],[],[],[0,1]]})
df
letter my_list
0 a [0, 1, 2]
1 b [1, 2]
2 c []
3 d []
4 e [0, 1]
What I'd like:
df
letter my_list
0 a [0, 1, 2]
1 b [1, 2]
4 e [0, 1]
What I'm trying:
df[df.my_list.map(lambda x: if len(x) !=0)]
... which returns an invalid syntax error. Any suggestions?