JamesHudson81
JamesHudson81

Reputation: 2273

multiply index value and column

I have the following df :

          A     B       C
A         A    A*B     A*C
B        A*B    B      B*C
C        A*C    B*C      C

I have on ther side a dfs with the values:

df0:  
A*B   3  
A*C   4
B*C   2

df1:
A     2 
B     8
C     3

Is there anyway I can substitute the values of the dataframe by the corresponding numerical values?

Upvotes: 1

Views: 69

Answers (1)

jezrael
jezrael

Reputation: 862751

It seeems you need replace:

print (df0)
     a
A*B  3
A*C  4
B*C  2
print (df1)
   b
A  2
B  8
C  3

df1 = df.replace(df0['a']).replace(df1['b'])
print (df1)
   A  B  C
A  2  3  4
B  3  8  2
C  4  2  3

Upvotes: 1

Related Questions