lundi 7 août 2017

Pandas, Python. Replace random subset of values in a column

I have a data frame from which a specific column (y1) has 3 possible values: -9, 1 and 2.

I would like to change a random sample of 1000 values which originally were 2 to -9.

I have tried this:

df.loc[df.y1 == "2", 'y1'].sample(1000) =="-9"

but it does not work.




Aucun commentaire:

Enregistrer un commentaire