0

I have a dataframe with the Columns "OfferID", "SiteID" and "CatgeoryID" which should represent an online ad on a website. I then want to add a new Column called "NPS" for the net promoter score. The values should be given randomly between 1 and 10 but where the OfferID, the SideID and the CatgeoryID are the same, they need to have the same value for the NPS. I thought of using a dictionary where the NPS is the key and the pairs of different IDs are the values but I haven't found a good way to do this.

Are there any recommendations?

Thanks in advance. Alina

1 Answer 1

1

The easiest would be first to remove all duplicates ; you can do this using :

uniques = df[['OfferID', 'SideID', 'CategoryID']].drop_duplicates(keep="first")

Afterwards, you can do something like this (note that your random values are not uniques) :

uniques['NPS'] = [random.randint(0, 100) for x in uniques.index]

And then :

df = df.merge(uniques, on=['OfferID', 'SideID', 'CategoryID'], how='left')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.