In the following pandas.DataFframe
:
df =
alfa beta ceta
a,b,c c,d,e g,e,h
a,b d,e,f g,h,k
j,k c,k,l f,k,n
How's this?
df = df[df['alpha'].str.split(',', expand=True)[2].isnull()]
Using expand=True
creates a new dataframe with one column for each item in the list. If the list has three or more items, then the third column will have a non-null value.
One problem with this approach is that if none of the lists have three or more items, selecting column [2]
will cause a KeyError
. Based on this, it's safer to use the solution posted by @Stephen Rauch.