mardi 4 septembre 2018

pandas dataframe assign random numbers group by

I want to randomly assign numbers to a given dataframe grouped by col1 so :

col1   col2 
MLB    1
MLB    1 
NBA    2
NFL    3
NFL    3
NFL    3

However, my script will go through multiple dataframes and I dont want MLB to always be associated with 1 so the next time it would output something like this.

col1   col2 
MLB    3
MLB    3 
NBA    1
NFL    2
NFL    2
NFL    2

My final output would just be col2 as I do not want to disclose col1, but i want to keep the rows associated by col2.




Aucun commentaire:

Enregistrer un commentaire