1

I'm working with data that has two separate IDs per item. When we pull data from most sources, we get a PLU/SKU—however, in one of our sources, we get an item number from our on-prem point-of-sale system. To solve this by hand, we have a master list that contains both the PLU and item number for each item, as a sort of key.

I have a dataframe that lists these item numbers alongside each item's quantity. What I need to do is search for the item number in the master list DF, grab the PLU from that row, and replace the original item number with the PLU. I've been looking into solutions all day and have failed to find something that I can comprehend. Would it be possible to iterate through each entry in the master list DF and then call a replace function on the item number DF? How would I do that, or something better? Thanks in advance!!

Here's what the data looks like across both, just as reference:

final_purch:

      PLU        QTY
0     12345634   4
1     78901256   29
2     34567878   2

master_df:

      ITEM       PLU
0     123456     12345634
1     789012     78901256
2     345678     34567878

EDIT: This post has been flagged as having an answer in the Merging 101 post, but this is a little more complicated than just merging, I think. I don't want to merge these. I want to reference the data in one to change the data in another, as there are duplicate entries with small bits of diverging data that would cause issues in a merge.

Kyle XCVI
  • 13
  • 3
  • `final_purch.merge(master_df, on='PLU', how='left')` – mozway Jun 27 '22 at 19:11
  • i've read your update. What is the expected result with the example input you have given? From what I understand so far, this is a task for merge, possibly with you copying/overwriting columns with results of the merge after that. If you don't agree then there are probably details about the input or additional rules that you haven't mentioned. Good luck :) – creanion Jul 03 '22 at 09:20

1 Answers1

0

This got closed before I could get an answer, so I just ended up merging and totally changing my approach to remove the unneeded data. Not ideal in the way I was hoping, but it got the job done.

Kyle XCVI
  • 13
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 06 '22 at 05:00