pandas 1.4.2

ParametersReturnsBackRef
dropna(self, axis: 'Axis' = 0, how: 'str' = 'any', thresh=None, subset: 'IndexLabel' = None, inplace: 'bool' = False)

See the User Guide <missing_data> for more on which values are considered missing, and how to work with missing data.

Parameters

axis : {0 or 'index', 1 or 'columns'}, default 0

Determine if rows or columns which contain missing values are removed.

how : {'any', 'all'}, default 'any'

Determine if row or column is removed from DataFrame, when we have at least one NA or all NA.

thresh : int, optional

Require that many non-NA values.

subset : column label or sequence of labels, optional

Labels along other axis to consider, e.g. if you are dropping rows these would be a list of columns to include.

inplace : bool, default False

If True, do operation inplace and return None.

Returns

DataFrame or None

DataFrame with NA entries dropped from it or None if inplace=True .

Remove missing values.

See Also

DataFrame.fillna

Replace missing values.

DataFrame.isna

Indicate missing values.

DataFrame.notna

Indicate existing (non-missing) values.

Index.dropna

Drop missing indices.

Series.dropna

Drop missing values.

Examples

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame({"name": ['Alfred', 'Batman', 'Catwoman'],
...  "toy": [np.nan, 'Batmobile', 'Bullwhip'],
...  "born": [pd.NaT, pd.Timestamp("1940-04-25"),
...  pd.NaT]})
... df name toy born 0 Alfred NaN NaT 1 Batman Batmobile 1940-04-25 2 Catwoman Bullwhip NaT

Drop the rows where at least one element is missing.

This example is valid syntax, but we were not able to check execution
>>> df.dropna()
     name        toy       born
1  Batman  Batmobile 1940-04-25

Drop the columns where at least one element is missing.

This example is valid syntax, but we were not able to check execution
>>> df.dropna(axis='columns')
       name
0    Alfred
1    Batman
2  Catwoman

Drop the rows where all elements are missing.

This example is valid syntax, but we were not able to check execution
>>> df.dropna(how='all')
       name        toy       born
0    Alfred        NaN        NaT
1    Batman  Batmobile 1940-04-25
2  Catwoman   Bullwhip        NaT

Keep only the rows with at least 2 non-NA values.

This example is valid syntax, but we were not able to check execution
>>> df.dropna(thresh=2)
       name        toy       born
1    Batman  Batmobile 1940-04-25
2  Catwoman   Bullwhip        NaT

Define in which columns to look for missing values.

This example is valid syntax, but we were not able to check execution
>>> df.dropna(subset=['name', 'toy'])
       name        toy       born
1    Batman  Batmobile 1940-04-25
2  Catwoman   Bullwhip        NaT

Keep the DataFrame with valid entries in the same variable.

This example is valid syntax, but we were not able to check execution
>>> df.dropna(inplace=True)
... df name toy born 1 Batman Batmobile 1940-04-25
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.frame.DataFrame.notna pandas.core.frame.DataFrame.isna pandas.core.series.Series.dropna pandas.core.frame.DataFrame.drop pandas.core.frame.DataFrame.groupby pandas.core.frame.DataFrame.value_counts pandas.core.frame.DataFrame.isnull pandas.core.frame.DataFrame.notnull

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#5873
type: <class 'function'>
Commit: