没有实际数据,很难回答这个问题,但是我想您正在
寻找这样的东西:
Top15['Citable docs per Capita'].corr(Top15['Energy Supply per Capita'])
That calculates the correlation between your two
columns
'Citable docs per Capita'
and
'Energy Supply per Capita'.
To give an example:
import pandas as pddf = pd.Dataframe({'A': range(4), 'B': [2*i for i in range(4)]}) A B0 0 01 1 22 2 43 3 6Then
df['A'].corr(df['B'])
gives
1as expected.
Now, if you change a value, e.g.
df.loc[2, 'B'] = 4.5 A B0 0 0.01 1 2.02 2 4.53 3 6.0
the command
df['A'].corr(df['B'])
returns
0.99586
which is still close to 1, as expected.
If you apply
.corrdirectly to your dataframe, it will return all pairwise
correlations between your columns; that’s why you then
observe
1sat the diagonal of your matrix (each column is perfectly
correlated with itself).
df.corr()
will therefore return
A BA 1.000000 0.995862B 0.995862 1.000000
在您显示的图形中,仅表示相关矩阵的左上角(我假设)。
有可能的情况下,你在哪里得到NaN您的解决方案的S -检查这个职位的一个例子。
如果要过滤高于或低于某个阈值的条目,可以检查此问题。如果要绘制相关
系数的热图,则可以检查该答案,如果然后遇到轴标签重叠的问题,请检查以下文章。



