Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing rows that contain empty column without pandas

Tags:

python

list

a_list = [ ["a", ""], ["b", "2"] ]

I have a list of lists as written above. Any suggestions on how to remove the row that contains an empty element (in this case the first list), without using pandas, so it returns:

a_list = [ ["b", "2"] ]
like image 581
dazzlingk Avatar asked Oct 26 '25 14:10

dazzlingk


1 Answers

Try:

a_list = [["a", ""], ["b", "2"]]

a_list = [l for l in a_list if "" not in l]
print(a_list)

Prints:

[['b', '2']]
like image 195
Andrej Kesely Avatar answered Oct 29 '25 05:10

Andrej Kesely