Random row selection in Pandas dataframe

后端 未结 6 1302
深忆病人
深忆病人 2020-11-28 02:52

Is there a way to select random rows from a DataFrame in Pandas.

In R, using the car package, there is a useful function some(x, n) which is similar to h

6条回答
  •  悲哀的现实
    2020-11-28 03:20

    Below line will randomly select n number of rows out of the total existing row numbers from the dataframe df without replacement.

    df=df.take(np.random.permutation(len(df))[:n])

提交回复
热议问题