减去python pandas中相关矩阵的列

时间:2017-12-14 17:59:43

标签: python pandas

我想减去浮点数的两个相关矩阵,但我不断得到NaNs。每个矩阵都是使用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  

它们大小相同但标题不同。我可以正常运行df['x_general']-1df2['x_general']-1

但如果我尝试df['x_general']-df2['x_general']我会得到NaNs,我无法弄清楚原因。

1 个答案:

答案 0 :(得分:2)

熊猫的美丽在于指数与你对齐。如果要忽略索引,请使用values属性。

df1 - df2.values