lundi 2 décembre 2019

Randomly select n rows from a dataframe t times?

How can I randomly select n rows from a dataframe t times?

For example: I have a dataframe df with 10 rows and I want to get 3 rows a time and repeat it 10 time.

a   value
n1  0.1
n2  0.2
n3  0.3
n4  0.4
n5  0.5
n6  0.6
n7  0.7
n8  0.8
n9  0.9
n10 1
Output
n1  0.1
n2  0.2
n3  0.3

n3  0.3
n5  0.5
n6  0.6

n1  0.1
n4  0.4
n3  0.3

n2  0.2
n4  0.4
n6  0.6

and so on...

In the end, I want to plot the score columns of these 10 small dataframes with another dataframe.

Till now, I have used the below function. But I do not know how to get the samples n times.

df_elements = df.sample(n=3)

Thanks




Aucun commentaire:

Enregistrer un commentaire