我有以下数据试图绘制3d线框。所有百分比的值,X轴:CPU,Y轴:内存,Z轴:Frame
Frame,10,20,30,40,50,60,70,80,90
10,40,46.66,46.67,33.33,53.33,60,40,20,46.67
20,53.33,40,53.3,46.67,53.33,53.33,46.67,40,53.33
30,46.67,46.67,46.67,33.33,66.67,33.3,60,40,40
40,46.67,46.67,40,53.33,40,46.67,33.33,33.33,60
df= pd.read_csv('data-graph.csv', sep=';')
df.index = df.Frame
del df['Frame']
raw_data = df
cpu = raw_data.columns.values.astype(float)
frame = raw_data.index.values.astype(float)
data = raw_data.values
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Z = data
X, Y = np.meshgrid(cpu, frame)
ax.plot_wireframe(X, Y, Z)
ax.set_xticks(cpu)
ax.set_yticks(frame[::2])
ax.set_xlabel('CPU')
ax.set_ylabel('Memory')
我正在检索下面的错误。
Traceback (most recent call last):
File "C:/Users/graph-update.py", line 7, in <module>
df.index = df.Frame
File "C:Userslearnminiconda3envstensorflowlibsite-packagespandascoregeneric.py", line 5274, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'Frame'
您似乎没有加载csv的标题,而将其加载到DataFrame。也就是说,'Frame'被读取为一个值,而不是列名。
打印df或其列,以确保它们被正确阅读。
您应该添加参数header=0
如下:
pd.read_csv('data-graph.csv', sep=';', header=0)
除此之外,您可能还应该将df.Frame
替换为df['Frame']
。
额外编辑:
添加参数index_col=0
,应该会得到您想要的结果,而不需要前4行代码。
检查pd的文档。read_csv .