Skip to content

API: add ignore_index keyword to dropna() and other similar functions #31725

Closed
@ghost

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  <NA>
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions