Removing an empty row from pandas dataframe

11,861

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.

Share:
11,861
nad
Author by

nad

Updated on June 04, 2022

Comments

  • nad
    nad almost 2 years

    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?