Python Forum

Full Version: How to check spec table in another df
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I have data frame as below:

group subgroup category name   T    S     P     R
A1      W           1           MAK     2    5.1  2     6 
A1      L            2           RAL      2    5     2     8
C1      L            2           GAH     2    6     1.2  6
C1      W           1           JKA      2    5     2     6
S5      W           1           NMP     2    5     2     6
S5      W           2           NMP     2    5     2     6
C1      W           2           AAA      2    5     2     6
A1      W           2           TTY      2    5.1  2    4  


Spec_df:
group subgroup category    T      S     P     R
A1      W           1               1.2  4.3   2.6    6 
A1      L            2                2    2.3   2     6
C1      L            2                2    6     1.2   6
C1      W           1                2    5     2     6
S5      W           1                1.5  5     2     6
S5      W           2                2     5     2     6
C1      W           2                2     5     2     6
A1      W           2                0.3  3.6   1.3   4 

I want to check  the spec for each "T, S,P" column based on group, subgroup, category. Any fast way to do this?  I did this using df.iterrows, and separte each condition based on  group, subgroup, category, which is become too big loop. 

if value in df > spec in spec_df, then mark as 1, else 0 for (T_F, S_F, P_F)
for example:

group subgroup category name   T_F    S _F    P_F   R
A1      W           1           MAK      1       0         0     6
A1      L            2           RAL       0        0        0     8