Advertisement
rajath_pai

Shuffle rows pandas

Apr 11th, 2023
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3.  
  4. # Read the CSV file into a pandas dataframe
  5. df = pd.read_excel('PA3_template.xlsx')
  6.  
  7. # Shuffle the rows
  8. df = df.sample(frac=1).reset_index(drop=True)
  9.  
  10. # Save the shuffled dataframe to a new CSV file
  11. df.to_excel('shuffled_PA3_template.xlsx', index=False)
  12.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement