lundi 26 mars 2018

python random customerID

everyone, I have an OrderID as shown below in the first column. In the second column, I need to assign Customer ID on random basis based on the following criteria:

Given same OrderID, the CustomerID should be same; CustomerID can repeat more than 1 times but be limited by 5 times since customer can buy more than once. For example, customer 123 has two OrderID: A01 and A03.

OrderID CustomerID
A01 123
A01 123
A02 145
A03 123
A02 145

the following is my try but did not meet my purpose.

np.random.seed(0)
df['CustomerID'] = np.random.randint(100, 999, len(df))




Aucun commentaire:

Enregistrer un commentaire