Pandas – How to shuffle a DataFrame rows
Let us see how to shuffle the rows of a DataFrame. We will be using the
sample() method of the pandas module to to randomly shuffle DataFrame rows in Pandas.
- Import the
- Create a DataFrame.
- Shuffle the rows of the DataFrame using the
sample()method with the parameter
fracas 1, it determines what fraction of total instances need to be returned.
- Print the original and the shuffled DataFrames.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course