Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dropping empty columns in pandas 0.23+ [duplicate]

Tags:

python

pandas

In earlier versions of pandas, you could drop empty columns simply with:

df.dropna(axis='columns')

However, dropna has been depreciated in later builds. How would one now drop multiple (without specifically indexing) empty columns from a dataframe?

like image 601
Évariste Galois Avatar asked Aug 10 '18 22:08

Évariste Galois


People also ask

How do I drop missing values in pandas?

Pandas DataFrame: dropna() function The dropna() function is used to remove missing values. Determine if rows or columns which contain missing values are removed. 0, or 'index' : Drop rows which contain missing values. 1, or 'columns' : Drop columns which contain missing value.


1 Answers

I am able to drop empty columns using dropna() with the current version of Pandas (0.23.4). The code I used is:

df.dropna(how='all', axis=1)

Looks like what is deprecated is passing multiple axes at once (i.e. df.dropna(how='all', axis = [0, 1]). You can read here that they made this decision - "let's deprecate passing multiple axes, we don't do this for any other pandas functions".

like image 82
Jen Avatar answered Oct 06 '22 09:10

Jen