0

I want to subtract two correlation matrices of floats but I keep getting NaNs. Each matrix was created using df.corr(). df:

x_general  y_general  z_general  aa_general  \
x_general            inf     0.638997       0.200524     -0.224471   
y_general        0.638997          inf       0.535362      0.210129   
z_general      0.200524     0.535362            inf      0.431792   
aa_general      -0.224471     0.210129       0.431792           inf   
bb_general        0.414017     0.413694       0.633447     -0.057247   

               bb_general  
x_general      0.414017  
y_general       0.413694  
z_general     0.633447  
aa_general     -0.057247  
bb_general            inf  

df2:

               x_precise  y_precise  z_precise  aa_precise  \
x_precise            inf     0.751819       0.468187      0.136465   
y_precise        0.751819          inf       0.713816      0.182763   
z_precise      0.468187     0.713816            inf      0.359914   
aa_precise       0.136465     0.182763       0.359914           inf   
bb_precise        0.489676     0.584030       0.805913     -0.066681   

               bb_precise  
x_precise      0.489676  
y_precise       0.584030  
z_precise     0.805913  
aa_precise     -0.066681  
bb_precise            inf  

They are the same size but have different headers. I can run df['x_general']-1 and df2['x_general']-1 just fine.

But if I try df['x_general']-df2['x_general'] I get NaNs and I can't figure out why.

Maria
  • 1,247
  • 1
  • 13
  • 21
  • 1
    Can you post examples of `df` and `df2`?https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – FHTMitchell Dec 14 '17 at 18:02

1 Answers1

2

The beauty of Pandas is that the indices align for you. If you want to ignore the indices, use the values attribute.

df1 - df2.values
piRSquared
  • 285,575
  • 57
  • 475
  • 624