[英]Dropping pandas rows based on lenght of list in a column
I have a pandas dataframe, one of the columns contains list of values like 我有一个熊猫数据框,其中一列包含值列表,例如
df = pd.DataFrame({'A': [11,22,33],
'B': [[4,5],[10,11,12], []]})
Now I want to drop all the rows that have empty lists in column 'B', Can anyone help please? 现在,我想删除“ B”列中所有具有空列表的行,有人可以帮忙吗? Thanks
谢谢
Using str.len
使用
str.len
df[df.B.str.len()!=0]
Out[223]:
A B
0 11 [4, 5]
1 22 [10, 11, 12]
Or 要么
df[df.B.astype(bool)]
Out[225]:
A B
0 11 [4, 5]
1 22 [10, 11, 12]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.