Pre-recorded question

Question #149
How to shuffle rows in a Pandas dataframe in Python?
Answer

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)

2 events in history
Answer by Alphonsio 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 Alphonsio 08/27/2020 at 05:27:37 PM
How to shuffle rows in a Pandas dataframe in Python?
# ID Query URL Count

Icons proudly provided by Friconix.