我有这样的数据
a b c d
a 1.32549 0.184661 NaN 0.0896751
b 0.184661 1.29026 NaN 0.156959
c NaN NaN NaN NaN
d 0.0896751 0.156959 NaN 1.22511
我要执行主成分分析。我收到这样的错误
in _assertFinite raise LinAlgError("Array must not contain infs or
NaNs") numpy.linalg.linalg.LinAlgError: Array must not contain infs or
NaNs
我正在尝试用替换功能替换NaN,但是它没有被替换。
import pandas as pd
import numpy as np
df = pd.read_csv('CHR1.txt', sep="\t", header=None)
rho = df.corr()
rho.replace('NaN', 0)
import plotly.plotly as py
eig_vals, eig_vecs = np.linalg.eig(rho)