jeudi 25 février 2021

How to generate 8 digit unique identifier to replace the existing one in python pandas

Let us say I have the following simple data frame. But in reality, I have hundreds thousands of rows like this.

df

ID              Sales
倀굖곾ꆹ譋῾理     100
倀굖곾ꆹ         50
倀굖곾ꆹ譋῾理     70
곾ꆹ텊躥㫆        60

My idea is that I want to replace the Chinese digit with randomly generated 8 digits something looks like below.

ID              Sales
13434535        100
67894335         50
13434535         70
10986467         60

The digits are randomly generated but they should keep uniqueness as well. For example, row 0 and 2 are same and when it replaced by a random unique ID, it should be the same as well.

Can anyone help on this in Python pandas? Any solution that is already done before is also welcome.




Aucun commentaire:

Enregistrer un commentaire