Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing an empty row from pandas dataframe

I am using this dataset and reading it through pandas dataframe. I need to work with the paperAbsrtract column only which has some missing data.

filename = "sample-S2-records"
df = pd.read_json(filename, lines=True) 
abstract = df['paperAbstract']

Because there are some missing data in the abstract dataframe, I want to remove those rows that are empty. So following the documentation, I do below

abstract.dropna(how='all')

But this doesn't remove those empty rows. They are still there in the abstract dataframe. What am I missing?

like image 835
nad Avatar asked Sep 17 '25 23:09

nad


1 Answers

You are missing the inplace argument by setting it to True or assigning this function's result to your dataframe.

# Solution 1: inplace = True:

abstract.dropna(how='all', inplace = True) 
# do operation inplace your dataframe and return None.

# Solution 2: assign the function result to your own dataframe:

abstract = abstract.dropna(how='all') 
# don't do operation inplace and return a dataframe as a result. 
# Hence this result must be assigned to your dataframe

Note: inplace default value is False.

like image 110
Rodolfo Bugarin Avatar answered Sep 20 '25 13:09

Rodolfo Bugarin