2

If a create a DataFrame Object, lets say df = pd.DataFrame({'A':range(5), 'B':range(5)}, and try to randomize some rows with df.reindex(np.random.permutation(df.index)) I get

>>> df = pd.DataFrame({'A':range(5), 'B':range(5)})
>>> df
   A  B
0  0  0
1  1  1
2  2  2
3  3  3
4  4  4
>>> df.reindex(np.random.permutation(df.index))
   A  B
3  0  0
0  1  1
1  2  2
2  3  3
4  4  4

Numpy version is 1.15.0

Pandas version is 0.23.3

Any idea why it is just mixing the indexes and not the whole rows?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 3
    I cannot reproduce the behaviour you are describing with v0.23.3 but the pandas way to do this is `df.sample(frac=1)`. – ayhan Aug 24 '18 at 22:11
  • 2
    I cant reproduce this either – rafaelc Aug 24 '18 at 22:27
  • What you sure you are using `reindex` and not just re-setting the index by changing `df.index` ? – rafaelc Aug 24 '18 at 22:27
  • The "df.sample(frac=1)" method indeed works, but I want to figure out why the prior method is misbehaving. By the way, I forgot to mention that I'm running Ubuntu 16.04 64 bit – Luis Bonilla Aug 26 '18 at 23:58
  • It's been several month since I asked this, but it seem that now it is behaving correctly (Maybe some Ubuntu update fixed the problem?) – Luis Bonilla Jan 24 '19 at 17:30

0 Answers0