IIUC pd.to_numeric NaN, fillna() 0 np.linalg.eigvals:
In [348]: df.apply(pd.to_numeric, errors='coerce')
Out[348]:
6M 1Y 2Y 4Y 5Y 10Y 30Y
6M NaN NaN NaN NaN NaN NaN NaN
1Y NaN 1.000000 0.946509 0.869504 0.812471 0.646870 0.508924
2Y NaN 0.946509 1.000000 0.934318 0.888068 0.742355 0.604819
4Y NaN 0.869504 0.934318 1.000000 0.976284 0.880398 0.776075
5Y NaN 0.812471 0.888068 0.976284 1.000000 0.911779 0.840466
10Y NaN 0.646870 0.742355 0.880398 0.911779 1.000000 0.951403
30Y NaN 0.508924 0.604819 0.776075 0.840466 0.951403 1.000000
In [350]: df.apply(pd.to_numeric, errors='coerce').fillna(0)
Out[350]:
6M 1Y 2Y 4Y 5Y 10Y 30Y
6M 0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1Y 0 1.000000 0.946509 0.869504 0.812471 0.646870 0.508924
2Y 0 0.946509 1.000000 0.934318 0.888068 0.742355 0.604819
4Y 0 0.869504 0.934318 1.000000 0.976284 0.880398 0.776075
5Y 0 0.812471 0.888068 0.976284 1.000000 0.911779 0.840466
10Y 0 0.646870 0.742355 0.880398 0.911779 1.000000 0.951403
30Y 0 0.508924 0.604819 0.776075 0.840466 0.951403 1.000000
In [351]: np.linalg.eigvals(df.apply(pd.to_numeric, errors='coerce').fillna(0))
Out[351]:
array([ 5.11329285, 0.7269089 , 0.07770957, 0.01334893, 0.02909796,
0.03964179, 0. ])
pd.to_numeric float:
In [352]: df.apply(pd.to_numeric, errors='coerce').dtypes
Out[352]:
6M float64
1Y float64
2Y float64
4Y float64
5Y float64
10Y float64
30Y float64
dtype: object
pd.to_numeric pandas version >= 0.17.0.
'n/a' , replace astype(float):
df.replace('n/a', 0).astype(float)
In [364]: df.replace('n/a', 0).astype(float)
Out[364]:
6M 1Y 2Y 4Y 5Y 10Y 30Y
6M 0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1Y 0 1.000000 0.946510 0.869504 0.812471 0.646870 0.508924
2Y 0 0.946510 1.000000 0.934318 0.888068 0.742355 0.604819
4Y 0 0.869504 0.934318 1.000000 0.976284 0.880398 0.776075
5Y 0 0.812471 0.888068 0.976284 1.000000 0.911779 0.840466
10Y 0 0.646870 0.742355 0.880398 0.911779 1.000000 0.951403
30Y 0 0.508924 0.604819 0.776075 0.840466 0.951403 1.000000
In [365]: np.linalg.eigvals(df.replace('n/a', 0).astype(float))
Out[365]:
array([ 5.11329285, 0.7269089 , 0.07770957, 0.01334893, 0.02909796,
0.03964179, 0. ])