mardi 7 août 2018

pandas: assign random numbers in given range to equal column values

I am working with a large dataset, and one of the columns has very long integers, like below:

       Column_1        Column_2
  1     A              12345123451
  2     B              12345123451
  3     C              12345123451
  4     D              23456789234
  5     E              23456789234
  6     F              34567893456

What is important here is not the actual number in Column_2, but when those numbers are the same while Column_1 is different. I would like to reassign the values of Column_2 randomly from a range of smaller numbers, say (1, 999).

       Column_1        Column_2
  1     A              120
  2     B              120
  3     C              120
  4     D              54
  5     E              54
  6     F              567

My issue is figuring a way to describe in a lambda function that each equal value in Column_2 needs the same random number.




Aucun commentaire:

Enregistrer un commentaire