Reputation:
I have the following dataset (name of columns are just an example):
Col1 Col2 Col3 Col4
12 321 42 []
31 42 542 [stop]
65 64 41 []
754 76 431 [python]
How can I select rows having not empty list in Col4
(i.e. second and fourth rows in the above sample)?
Upvotes: 1
Views: 1302
Reputation: 4618
could do something like this:
df[df['Col4'].astype(str) != '[]']
this just converts the column to strings to make it easier to compare an empty list
or:
df[df['Col4'].str.len() != 0]
Upvotes: 1
Reputation: 7594
You can check the length of the list:
df = df[df['Col4'].apply(lambda x: len(x)) > 0]
Upvotes: 0