Skip to content

ENH: add ignore_index to DataFrame / Series.sample  #38581

Closed
@erfannariman

Description

@erfannariman

Is your feature request related to a problem?

When sampling a dataframe / series we get the original index back by default, which is good, but we should add an option to ignore the index to keep it consistent with other methods like drop_duplicates and explode for example.

Describe the solution you'd like

Add ignore_index argument to Series/DataFrame.sample.

API breaking implications

None as far as I can tell.

df = pd.DataFrame(
    {"col1": range(10, 20), "col2": range(20, 30), "colString": ["a"] * 10}
)
df.sample(n=3, ignore_index=True)

   col1  col2 colString
0    14    24         a
1    17    27         a
2    11    21         a

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions