2

The following seems to work:

import pandas as pd
import sklearn
df = sklearn.datasets.load_iris()
df = pd.DataFrame(df.data, columns=df.feature_names)
df.shuffle()

However this shuffle function seems not to be a documented DataFrame function?

Is this an internal function we are not supposed to use?

2
  • I'm voting to close this question because it was caused by a typo and it not reproducible Commented Aug 7 at 11:38
  • I am a bit torn here: technically, you could easily make your observation reproducible with your code snippet by prepending import janitor to it – and it would still be true that in the official Pandas doc, the now-available df.shuffle() method could not be found. All in all, I believe the question and its answers still have merit for a wider audience, but I guess it is a bit of an edge case. Commented Aug 7 at 11:50

2 Answers 2

7

If it "works" in some environment, it's likely due to a custom extension or monkey patching.
In Pandas 2.3.1, the correct way to shuffle a DataFrame is:
df = df.sample(frac=1).reset_index(drop=True)
df.shuffle() is not part of the standard Pandas API.

Sign up to request clarification or add additional context in comments.

Comments

2

It was pyjanitor. I forgot that it was imported.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.