0

I have the following data trying to plot a 3d wireframe. All the values in percentage, X Axis: CPU,Y Axis: Memory,Z Axis: 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')

I am retrieving below error.

Traceback (most recent call last):
File "C:/Users/graph-update.py", line 7, in <module>
df.index = df.Frame
File "C:\Users\learn\miniconda3\envs\tensorflow\lib\site-packages\pandas\core\generic.py", line 5274, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'Frame'

1 Answer 1

1

You don't seem to be loading the headers of the csv while loading it on a DataFrame. Meaning, 'Frame' is read as a value instead of a column name.

Print your df or its columns to ensure they are read properly.

You should add the parameter header=0 as follows:

pd.read_csv('data-graph.csv', sep=';', header=0)

Other than that you should probably also replace df.Frame with df['Frame'].

extra edit:

adding the parameter index_col=0 as well, should give you the desired result without the first 4 lines of code.

Check the documentation for pd.read_csv .

Sign up to request clarification or add additional context in comments.

2 Comments

Hi @JosephDoun, thanks for your response. After changing I am retrieving below error File "C:\Users\learn\miniconda3\envs\tensorflow\lib\site-packages\pandas\core\indexes\base.py", line 2646, in get_loc return self._engine.get_loc(key)
I updated my answer. I hope this helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.