Lod*_*e66 8 nan scipy pearson pandas
快速提问:有没有办法在scipy中使用'dropna'和Pearson的r函数?我正在将它与熊猫一起使用,我的一些数据中有漏洞.我知道你曾经能够在较旧版本的scipy中使用Spearman的r来抑制'nan' ,但是现在缺少这个功能.
在我看来,这似乎是一种不妥协,所以我想知道我是否遗漏了一些明显的东西.
我的代码:
for i in range(len(frame3.columns)):
correlation.append(sp.pearsonr(frame3.iloc[ :,i], control['CONTROL']))
Run Code Online (Sandbox Code Playgroud)
Ami*_*ory 11
你可以np.isnan
像这样使用:
for i in range(len(frame3.columns)):
x, y = frame3.iloc[ :,i].values, control['CONTROL'].values
nas = np.logical_or(x.isnan(), y.isnan())
corr = sp.pearsonr(x[~nas], y[~nas])
correlation.append(corr)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6602 次 |
最近记录: |