Pandas DataFrame.dropna() Method
Last Updated : 25 Jun, 2025
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())
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'))
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))
OutputEmpty 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))
OutputEmpty 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)
Explanation: Only the last row has no missing values. inplace=True updates df directly without returning a new object.
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