python-machine-learning-book icon indicating copy to clipboard operation
python-machine-learning-book copied to clipboard

Chapter 8: Shuffling the DataFrame in newer versions of pandas

Open steveneale opened this issue 6 years ago • 1 comments

Just a note in case it's helpful to anyone else - I seemed to be getting 100% accuracy with the on-line sentiment analysis classifier (pages 246-246), but it turned out to be because the code used to shuffle the dataset before exporting it to CSV on page 235 hadn't worked.

In the version of pandas I'm using (0.23.4), it looks like df.index.values is needed in order to get the indexes of a DataFrame as a list. So, this:

df = df.reindex(np.random.permutation(df.index))

now needs to be this:

df = df.reindex(np.random.permutation(df.index.values))

Hope that helps someone!

steveneale avatar Nov 19 '18 12:11 steveneale

Thanks for helping !

Alcormizarsouha avatar Oct 18 '22 17:10 Alcormizarsouha