Last active
August 22, 2020 08:40
-
-
Save cadrev/6b91985a1660f26c2742 to your computer and use it in GitHub Desktop.
Shuffle the rows of a python pandas dataframe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks