Home > database >  Removing entire rows from a dataframe for which a specified column value contains null
Removing entire rows from a dataframe for which a specified column value contains null

Time:11-01

Using python and pandas I am trying to remove entire rows from a dataframe where a value in a specific column is a null: I have tried the following code using a for loop:

for row in dataframe.index:
    if pd.isnull(dataframe['Column'][i]):
        dataframe[.drop([i], axis=0, inplace=False)

However I got the following error:

NameError: name 'i' is not defined

Does anybody have a suggestion?

CodePudding user response:

Use pandas.DataFrame.dropna:

In your case, it would be like this:

dataframe.dropna(subset=['Column'], inplace=True, axis=0)

CodePudding user response:

Use pandas.DataFrame.dropna: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html

In your case, it would be like this:

dataframe.dropna(subset=['Column'], inplace=True, axis=0)

  • Related