Pandas – How to shuffle a DataFrame rows Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report Let us see how to shuffle the rows of a DataFrame. We will be using the sample() method of the pandas module to randomly shuffle DataFrame rows in Pandas. Algorithm : Import the pandas and numpy modules. Create a DataFrame. Shuffle the rows of the DataFrame using the sample() method with the parameter frac as 1, it determines what fraction of total instances need to be returned. Print the original and the shuffled DataFrames. python # import the modules import pandas as pd import numpy as np # create a DataFrame ODI_runs = {'name': ['Tendulkar', 'Sangakkara', 'Ponting', 'Jayasurya', 'Jayawardene', 'Kohli', 'Haq', 'Kallis', 'Ganguly', 'Dravid'], 'runs': [18426, 14234, 13704, 13430, 12650, 11867, 11739, 11579, 11363, 10889]} df = pd.DataFrame(ODI_runs) # print the original DataFrame print("Original DataFrame :") print(df) # shuffle the DataFrame rows df = df.sample(frac = 1) # print the shuffled DataFrame print("\nShuffled DataFrame:") print(df) Output : Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century. Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve. Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore. Last Updated : 28 Nov, 2022 Like Article Save Article Previous Check if a value exists in a DataFrame using in & not in operator in Python-Pandas Next Python - Test for Unique Frequencies Share your thoughts in the comments Add Your Comment Please Login to comment...