Python Forum
How to grep corresponding value in another df
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to grep corresponding value in another df
#1
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
Reply
#2
Sounds like you want to join the DataFrames. DataFrame.join() operates similarly to a SQL join if you're familiar.
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  use subprocess on linux\pi wwith a "grep " command korenron 2 2,795 Oct-19-2021, 10:52 AM
Last Post: DeaD_EyE
  grep value files enigma619 0 1,078 Mar-04-2020, 02:21 PM
Last Post: enigma619
  2 forms of this tool grep command Lylyhannah 0 1,567 Jan-21-2019, 08:21 AM
Last Post: Lylyhannah
  grep command based on lines in a pattern file Skaperen 1 1,589 Jan-07-2019, 10:23 AM
Last Post: Gribouillis
  windows grep messed up Larz60+ 4 3,599 Mar-27-2017, 01:58 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020