w3resource

Pandas DataFrame: dropna() function

DataFrame-dropna() function

The dropna() function is used to remove missing values.

Syntax:

DataFrame.dropna(self, axis=0, how='any', thresh=None, subset=None, inplace=False)

Parameters:

Name Description Type/Default Value Required / Optional
axis             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.
{0 or ‘index’, 1 or ‘columns’}
Default Value: 0
Required
how  Determine if row or column is removed from DataFrame, when we have at least one NA or all NA.
  • ‘any’ : If any NA values are present, drop that row or column.
  • ‘all’ : If all values are NA, drop that row or column.
 {‘any’, ‘all’}
Default Value: ‘any’
Required
thresh  Require that many non-NA values. int Optional
subset  Labels along other axis to consider, e.g. if you are dropping rows these would be a list of columns to include. array-like Optional
inplace  If True, do operation inplace and return None. bool
Default Value: False
Required

Returns: DataFrame
DataFrame with NA entries dropped from it.

Example:


Download the above Notebook from here.

Previous: DataFrame - take() function
Next: DataFrame-fillna() function