mercredi 4 septembre 2019

How can randomly select records of a data frame based on values of a column of that data frame, while there are some conditions as well?

I have a dataset like this:

enter image description here

df

I want to select "MI" number of samples and add to another dataframe. This is my code,but it does not work

Blockquote

All_M=pd.DataFrame() A = df['ranking'].min()

for i in range(0 , len(df)): x6 = df[(df['ranking'] == A)].apply(lambda x:x.sample(int(df["MI"][i])).reset_index(drop=True)) All_M= x6.append(All_M) A = A + 1




Aucun commentaire:

Enregistrer un commentaire