Pandas DataFrame: dropna() function - w3resource (2024)

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:

NameDescriptionType/Default Value Required / Optional
axisDetermine 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
howDetermine 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
threshRequire that many non-NA values.intOptional
subsetLabels along other axis to consider, e.g. if you are dropping rows these would be a list of columns to include.array-likeOptional
inplaceIf True, do operation inplace and return None.bool
Default Value: False
Required

Returns: DataFrame
DataFrame with NA entries dropped from it.

Example:


Download the Pandas DataFrame Notebooks from here.

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



Pandas DataFrame: dropna() function - w3resource (2024)
Top Articles
Latest Posts
Article information

Author: Dong Thiel

Last Updated:

Views: 5822

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.