0

I have a csv file which i am importing but i want to shuffle the data rows in pandas.

df = pd.read_csv('example.csv',header=0) 
1800 rows, 31 columns

What is the easiest way to do this? I have found my confusing examples but are there any built in functions in pandas?

I tried this but it is not working.

df = df.apply(numpy.random.shuffle)

All i am looking for is just 1 line of code. Nothing complicated

pbu
  • 2,982
  • 8
  • 44
  • 68
  • `df.reindex(np.random.permutation(df.index))` would work - see the the linked question for other ideas. – Alex Riley Feb 10 '15 at 14:36
  • Would this work? This line seems to use numpy and back to pandas `df.apply(np.random.shuffle(df.values),axis=0)` – pbu Feb 10 '15 at 14:40

0 Answers0