Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a better way to shuffle the rows of a data frame and read them in chunks than what I currently have?

What I have tried:

This is my attempt:

df = pd.read_csv("ExtractedData.csv")
df_sampled = df.sample(frac=1)
df_sampled.to_csv("Sampled.csv", mode='w')
df_shuffled = pd.read_csv("Sampled.csv", chunksize=1000)

While it works, there has to be a way to combine these steps. Any help is much appreciated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900