API: add ignore_index keyword to dropna() and other similar functions · Issue #31725 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
Code Sample
Before
df = pd.DataFrame({'A': [0, pd.NA, 1]}) df.dropna().reset_index(drop=True)
After
df = pd.DataFrame({'A': [0, pd.NA, 1]}) df.dropna(ignore_index=True)
Problem description
I have noticed a lot of dataframe reshaping functions acquiring the ignore_index
keyword. (e.g. #30114). I think df.dropna()
is a good candidate for this keyword, as are any other functions which change the index from being a consecutive sequence of integers
Expected Output
In [1]: import pandas as pd
In [2]: df = pd.DataFrame({'A': [0, pd.NA, 1]})
In [3]: df Out[3]: A 0 0 1 2 1
In [4]: df.dropna().reset_index(drop=True) Out[4]: A 0 0 1 1
In [5]: df.dropna(ignore_index=True) Out[5]: A 0 0 1 1