0

I searched a lot but I can't solve my problem - maybe someone can give me a hint:

I have two Panda Dataframes, df1 and df2, with these columns:

EAN PRODUCT-NAME OLD-DESCRIPTION PURCHASE-PRICE SALES-PRICE

EAN NEW-PRODUCT-NAME NEW-DESCRIPTION

I want to locate a product in df1 by the EAN number, and replace it's name and description with the new name & description in the corresponding product in df2. It is important to know, that the first dataset is bigger and not every product will get a new name and description. I can't just replace the whole columns.

I have to go take the EAN numbers in df2, search for them in df1 to find the right product, and replace the name and description in df2.

I tried various methods like replace, isin, and even thought about nesting two loopsto solve the problem. But I might think to complicated...

2 Answers 2

1

EAN column is not common between both tables. df1 is way bigger.

I thought about something like this, but this is not elegant at all...

for x in df1.index:
   for y in df2.index:
      if df1.loc[x, "EAN"] == df2.loc[y, "EAN"]:
         print ("Found!") 
         df1["OLD-DESCRIPTION"] = df2["NEW-DESCRIPTION"]
Sign up to request clarification or add additional context in comments.

Comments

0

Assumption : EAN column is common between 2 table

df3=pd.merge(df1,df2 , on= 'EAN',how= 'Outer')

further you can filter colums which you need and also rename it as needed.

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.