Question #128
Submitted by Answiki
on 08/27/2020 at 05:27:37 PM UTC
How to shuffle rows in a Pandas dataframe in Python?
Merged questions
Answer
Submitted by Answiki
on 08/27/2020 at 05:30:09 PM UTC
In Python, to shuffle rows in a dataframe, use the .sample() method:
df.sample(frac=1)
If you wish to shuffle and reset the index, use:
df = df.sample(frac=1).reset_index(drop=True)
Answer by Answiki on 08/27/2020 at 05:30:09 PM
In Python, to shuffle rows in a dataframe, use the .sample() method:
df.sample(frac=1)
If you wish to shuffle and reset the index, use:
df = df.sample(frac=1).reset_index(drop=True)
Question by Answiki 08/27/2020 at 05:27:37 PM
How to shuffle rows in a Pandas dataframe in Python?
| # | ID | Query | URL | Count |
|---|---|---|---|---|
| 0 | 11794 | en | https://en.ans.wiki/128/how-to-shuffle-rows-in-a-pandas-dataframe-in-python | 7 |
Icons proudly provided by Friconix.