![]() |
How to grep corresponding value in another df - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to grep corresponding value in another df (/thread-30273.html) |
How to grep corresponding value in another df - Mekala - Oct-13-2020 Hi, I have two data frames, df1: Model group type sub1 sub2 rank1 status 200B R2R v1 5 6 3 Y 200C Mon v2 12 3.2 9 Y 200B Mon v1 3 8.9 5 Y group type item 200B 200C R2R v1 sub1 2 6 R2R v2 sub1 1 4 R2R v1 sub2 3 2 R2R v2 sub2 6 3 Mon v1 sub1 1 5 Mon v2 sub1 2.0 -1 Mon v1 sub2 11 12 Mon v2 sub2 3 3 Mon v1 rank1 1 1 Mon v2 rank1 2.0 5 R2R v1 rank1 1 3 R2R v2 rank1 2 6 R2R v1 rank1 5 4 R2R v2 rank1 7 1 for each value in df1 (sub1, sub2, rank1), I want extarct the corressponding value in df2 and calculate difference. Model group type sub1 sub2 rank1 status sub1_d sub2_d rank1_d 200B R2R v1 5 6 3 Y 3 3 2 200C Mon v2 12 3.2 9 Y 13 0.2 4 200B Mon v1 3 8.9 5 Y 2 -2.1 4 RE: How to grep corresponding value in another df - stullis - Oct-13-2020 Sounds like you want to join the DataFrames. DataFrame.join() operates similarly to a SQL join if you're familiar. RE: How to grep corresponding value in another df - Mekala - Oct-13-2020 I am not very familiar of DataFrame.join(). My purpose is to take "df" is actual, and df2 is target. and want to calculate difference between actual (in df1) and target in df2 for sun1, sub2, rank1 columns |