Skip to content

Instantly share code, notes, and snippets.

@cadrev
Last active August 22, 2020 08:40
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cadrev/6b91985a1660f26c2742 to your computer and use it in GitHub Desktop.
Save cadrev/6b91985a1660f26c2742 to your computer and use it in GitHub Desktop.
Shuffle the rows of a python pandas dataframe
'''
Title : Pandas Row Shuffler
Author : Felan Carlo Garcia
'''
import numpy as np
import pandas as pd
def shuffler(filename):
df = pd.read_csv(filename, header=0)
# return the pandas dataframe
return df.reindex(np.random.permutation(df.index))
def main(outputfilename):
shuffler('test.csv').to_csv(outputfilename, sep=',')
if __name__ == '__main__':
main('final-output.csv')
@ArashAzizi222
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment