我正在尝试从 CSV 文件导入角膜地形图数据。切片轴并将所有转换为 np.array 后,imshow 无法绘制数据,显示错误消息
"raise TypeError("dtype {}的图像数据不能转换为" TypeError: dtype对象的图像数据不能转换为float"
如果我不将数据转换为 np.array 而只是写
topo1 = df.iloc[1:142, 1:142].astype(dtype=float)
错误消息说:
“返回 arr.astype(dtype,copy=True)ValueError:无法将字符串转换为浮点数:'-'”
所以在我看来,我的数据中某处有一个“-”字符无法转换为浮点数,但我无法找到并删除它。
有人可以帮我解决这个问题吗?
一切顺利,佩曼。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data= pd.read_csv (r'myfile.CSV', header=None)
df = pd.DataFrame(data=data)
# the first row of df is the x-axis range and the first column is the y-axis range
X= np.array(df.iloc[0, 1:142].astype(float))
Y= np.array(df.iloc[1:142, 0].astype(float))
topo1 = np.array(df.iloc[1:142, 1:142].astype(dtype=float, errors = 'ignore'))
plt.imshow(topo1)
plt.show()