首页 > 解决方案 > 如何在包含空列表的数据框中删除行?

问题描述

我创建了一个包含 3 列的数据框,第三列包含列表,我想在该单元格中删除包含空列表的行。

我试过了

df[df.numbers == []] and df[df.numbers == null]
but nothing works. 
name    country    numbers

Lewis   Spain      [1,4,6]
Nora    UK         []
Andrew  UK         [3,5]

结果将是一个没有 Nora 行的数据框

标签: python-3.xpandasdataframe

解决方案


嗯检查bool

df[df.numbers.astype(bool)]

推荐阅读