TypeError: ‘(slice(None, None, None), slice(None, None, None))‘ is an invalid key
TypeError: '(slice(None, None, None), slice(None, None, None))' is an invalid key的解决方法
·
这种错误很常见,主要可能是我们操作的(df)是一个dataframe,应该正确的运用索引,loc
或者iloc
。
例如,我遇到一次错误:
factors = data[:, :] # 其它因素
m, n = factors.shape
corrs = np.zeros((n, n))
for i in range(n):
print(i)
for j in range(n):
corrs[i, j] = dist_corr(factors[:, i], factors[:, j])
corrs
TypeError: '(slice(None, None, None), slice(None, None, None))' is an invalid key
更正后:
factors = data.iloc[:, :] # 其它因素
m, n = factors.shape
corrs = np.zeros((n, n))
for i in range(n):
print(i)
for j in range(n):
corrs[i, j] = dist_corr(factors.iloc[:, i], factors.iloc[:, j])
corrs
更多推荐
已为社区贡献36条内容
所有评论(0)