Categories
Python Answers

How to shuffle python Pandas DataFrame rows?

Spread the love

To shuffle python Pandas DataFrame rows, we call the data frame sample method.

For instance, we write

df.sample(frac=1)

to call sample on the df data frame.

The frac keyword argument specifies the fraction of rows to return in the random sample, so frac=1 means to return all rows in random order.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *