Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Pandas DataFrame.dropna() Method
Next article icon

Pandas DataFrame.dropna() Method

Last Updated : 25 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

DataFrame.dropna() function remove missing values (NaN or None) from a DataFrame. It can drop entire rows or columns depending on the axis and threshold you specify. This method is commonly used during data cleaning to eliminate incomplete data before analysis.

For Example:

Python
import pandas as pd import numpy as np df = pd.DataFrame({'A': [1, np.nan, 3], 'B': [4, 5, None]}) print(df.dropna()) 

Output
     A    B 0  1.0  4.0 

Explanation: By default, dropna() removes rows with any missing values. Row 0 has no missing data, so it's kept. Rows 1 and 2 contain NaN or None, so they're dropped. Only row 0 remains.

Syntax

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

Parameters:

Parameter

Description

axis

0 to drop rows (default), 1 to drop columns

how

'any' (default): drop if any value is missing and 'all': drop if all are missing

thresh

Minimum number of non-NA values required to keep the row/column

subset

Labels to consider for NA checks (subset of columns)

inplace

If True, modifies the original DataFrame; if False (default), returns a new one

Returns: A new DataFrame with the specified rows or columns removed unless inplace=True.

Examples

Example 1: We drop rows only if all values are missing.

Python
import pandas as pd import numpy as np  df = pd.DataFrame({'A': [np.nan, np.nan, 3], 'B': [None, np.nan, 4]}) print(df.dropna(how='all')) 

Output
     A    B 2  3.0  4.0 

Explanation: Only the first two rows contain all missing values. The third row is kept because it has valid values.

Example 2: We drop columns that contain any missing values by setting axis=1.

Python
import pandas as pd import numpy as np df = pd.DataFrame({'A': [1, 2, np.nan], 'B': [4, None, 6]}) print(df.dropna(axis=1)) 

Output
Empty DataFrame Columns: [] Index: [0, 1, 2] 

Explanation: Since both columns 'A' and 'B' have at least one missing value (NaN or None), using dropna(axis=1) drops them. This leaves an empty DataFrame with only row indices and no columns.

Example 3: We use thresh to keep rows that have at least 2 non-null values.

Python
import pandas as pd import numpy as np  df = pd.DataFrame({'A': [1, np.nan, 3], 'B': [None, 5, None]}) print(df.dropna(thresh=2)) 

Output
Empty DataFrame Columns: [A, B] Index: [] 

Explanation: thresh=2 keep rows that have at least 2 non-null values. Each row in the DataFrame has only 1 non-null value, so all rows are dropped.

Example 4: In this example, we drop rows that have missing values only in a specific column ('A') using subset.

Python
import pandas as pd import numpy as np  df = pd.DataFrame({'A': [1, np.nan, 3], 'B': [4, 5, None]}) print(df.dropna(subset=['A'])) 

Output
     A    B 0  1.0  4.0 2  3.0  NaN 

Explanation: Only rows where column 'A' is NaN are dropped. Other missing values are ignored.

Example 5: In this example, we use inplace=True to modify the DataFrame directly.

Python
import pandas as pd import numpy as np  df = pd.DataFrame({'X': [1, np.nan, 3], 'Y': [np.nan, 5, 6]}) df.dropna(inplace=True) print(df) 

Output
     X    Y 2  3.0  6.0 

Explanation: Only the last row has no missing values. inplace=True updates df directly without returning a new object.


Next Article
Pandas DataFrame.dropna() Method

K

Kartikaybhutani
Improve
Article Tags :
  • Misc
  • Python
  • python-modules
Practice Tags :
  • Misc
  • python

Similar Reads

    Pandas DataFrame.astype()-Python
    DataFrame.astype() function in pandas cast a pandas object such as a DataFrame or Series to a specified data type. This is especially useful when you need to ensure that columns have the correct type, such as converting strings to integers or floats to strings. For example:Pythonimport pandas as pd
    3 min read
    Python | Pandas DataFrame.set_index()
    Pandas DataFrame.set_index() method sets one or more columns as the index of a DataFrame. It can accept single or multiple column names and is useful for modifying or adding new indices to your DataFrame. By doing so, you can enhance data retrieval, indexing, and merging tasks.Syntax: DataFrame.set_
    3 min read
    Pandas DataFrame.reset_index()
    In Pandas, reset_index() method is used to reset the index of a DataFrame. By default, it creates a new integer-based index starting from 0, making the DataFrame easier to work with in various scenarios, especially after performing operations like filtering, grouping or multi-level indexing. Example
    3 min read
    Python | Pandas Dataframe.at[ ]
    Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas at[] is used to return data in a dataframe at the passed location. The passed l
    2 min read
    Pandas DataFrame iterrows() Method
    iterrows() method in Pandas is a simple way to iterate over rows of a DataFrame. It returns an iterator that yields each row as a tuple containing the index and the row data (as a Pandas Series). This method is often used in scenarios where row-wise operations or transformations are required. Exampl
    4 min read
    Python | Pandas Series.iteritems()
    Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.iteritems() function iterates
    2 min read
    Pandas.to_datetime()-Python
    pandas.to_datetime() converts argument(s) to datetime. This function is essential for working with date and time data, especially when parsing strings or timestamps into Python's datetime64 format used in Pandas. For Example:Pythonimport pandas as pd d = ['2025-06-21', '2025-06-22'] res = pd.to_date
    3 min read
    Python | pandas.to_numeric method
    Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. pandas.to_numeric() is one of the general functions in Pandas which is used to convert
    2 min read
    Pandas DataFrame.to_string-Python
    Pandas is a powerful Python library for data manipulation, with DataFrame as its key two-dimensional, labeled data structure. It allows easy formatting and readable display of data. DataFrame.to_string() function in Pandas is specifically designed to render a DataFrame into a console-friendly tabula
    5 min read
    pandas.concat() function in Python
    pandas.concat() function concatenate two or more pandas objects like DataFrames or Series along a particular axis. It is especially useful when combining datasets either vertically (row-wise) or horizontally (column-wise). Example:Pythonimport pandas as pd df1 = pd.DataFrame({'A': ['A0', 'A1'], 'B':
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences