Help us understand the problem. What is going on with this article?

メモ:DataFrame で順序をシャッフルする方法

More than 1 year has passed since last update.

注: index が連番である前提

import numpy as np
def shuffle_df(df):
    shuffler = np.random.permutation(len(df))  # シャッフルされた番号の配列を返す
    df = df.take(shuffler)  # 渡された番号順のDataFrameを返す
    return df
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away