我想关联具有相同列名Length date(i)
的df1
和df2
。两个数据帧都具有NaN
的单元格。我想忽略这些单元格,跳过两个数据帧中的这一行。
measurements = 10
for i in range(1,measurements+1):
cor_len = pearsonr(df1['Length date(' + str(i) + ')'], df2['Length date(' + str(i) + ')'])
到目前为止,我总是得到:
ValueError:数组不能包含infs或NaNs
两个df看起来都像:
Length date(1) Length date(2) Length date(3) Length date(4) Length date(5) Length date(6)
8.512326 5.758995 39.743087 52.811855 75.285461 65.122357
18.852476 56.067361 93.113099 177.415235 184.472485 161.042771
92.391779 53.909429 76.507877 149.716421 147.524874 110.94987
NaN 21.220149 NaN NaN NaN NaN
NaN 27.559950 NaN NaN NaN NaN
此解决方案运行良好:
for i in range(1,measurements+1):
xl = dfr['Length date(' + str(i) + ')'].dropna()
yl = df['Length date(' + str(i) + ')'].dropna()
dl = pd.concat([xl,yl], axis = 1)
dl = dl.dropna()
cor_len = dl.corr()