Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I drop rows in data frames which contains empty lists?

I have created a data frame with 3 columns, the third one contains lists, I want to drop rows that contains an empty list in that cell.

I have tried with

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]

The result will be a data frame without Nora's row

like image 467
Nelly Louis Avatar asked Jul 16 '19 15:07

Nelly Louis


People also ask

What is a correct Pandas method for removing rows that contains empty cells?

Drop Empty Rows or Columns If you're looking to drop rows (or columns) containing empty data, you're in luck: Pandas' dropna() method is specifically for this.

How do you drop all rows with missing values in Pandas?

To drop all the rows which contain only missing values, pass the value 0 to the axis parameter and set the value how='all' .

How do you drop rows contain NaN?

To drop all the rows with the NaN values, you may use df. dropna().


1 Answers

Umm check bool

df[df.numbers.astype(bool)]
like image 63
BENY Avatar answered Sep 26 '22 02:09

BENY