Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
erfannariman opened this issue Dec 19, 2020 · 7 comments · Fixed by #42168
Closed

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

erfannariman opened this issue Dec 19, 2020 · 7 comments · Fixed by #42168
Assignees
Milestone

Comments

@erfannariman
Copy link
Member

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
@erfannariman erfannariman added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 19, 2020
@skvrahul
Copy link
Contributor

take

@skvrahul
Copy link
Contributor

skvrahul commented Dec 20, 2020

@erfannariman Doesn't reset_index serve the same purpose in this case?
i.e

df.sample(n=3).reset_index()

@erfannariman
Copy link
Member Author

I actually wanted to work on this if you don't mind. I was waiting till one of the core devs approved the change.

@jreback
Copy link
Contributor

jreback commented Dec 20, 2020

yep this is ok to do

@erfannariman
Copy link
Member Author

Thanks @jreback , @skvrahul you mind if I pick this one up? My bad I didn't "take" before.

@skvrahul
Copy link
Contributor

Thanks @jreback , @skvrahul you mind if I pick this one up? My bad I didn't "take" before.

Sure. No worries! :)
I've unassigned myself

@erfannariman
Copy link
Member Author

take

@jreback jreback added this to the 1.3 milestone Dec 22, 2020
@rhshadrach rhshadrach removed the Needs Triage Issue that has not been reviewed by a pandas team member label Dec 26, 2020
@simonjayhawkins simonjayhawkins removed this from the 1.3 milestone May 25, 2021
@jreback jreback added this to the 1.3 milestone Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants