mercredi 27 novembre 2019

randomly record array values to data frame column with if condition

I have an array with randomly generated data (Y1age). I need to randomly assign values from this array (Y1age) to a column ('age') in data frame if a condition is met.

I tried this:

df.loc[df['year'] == "Y1", 'age'] = (np.random.choice(Y1age))

This only chooses I value and assigns to all cells if a condition is met: head of the data frame:




Aucun commentaire:

Enregistrer un commentaire