wow
wow

Reputation: 13

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

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?

Upvotes: 0

Views: 41

Answers (1)

Bashton
Bashton

Reputation: 339

Use pandas.DataFrame.dropna:

In your case, it would be like this:

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

Upvotes: 1

Related Questions