Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am practicing and out of ideas anymore on how to plot all column and just the two columns only. i have this code here and it didn't at plotting the datas. it only says that
Traceback (most recent call last):
  File "C:/pythonnnn/pandas/midterm list.py", line 23, in <module>
    b.plot(x='ylevel', y='average')
AttributeError: 'dict' object has no attribute 'plot'


pls help at plotting 2 column or all columns.

What I have tried:

import pandas as pd
import matplotlib.pyplot as plt
n=int(input("How many times: "))
name=[]
section=[]
ylevel=[]
average=[]

for i in range(n):
    sn = input("Name: ")
    sec=input("Section: ")
    yl=input("Level: ")
    avg=input("Average: ")

    name.append(sn)
    section.append(sec)
    ylevel.append(yl)
    average.append(avg)

b={'Name': name,'Sec':section,'Level':ylevel,'Average':average}
c=pd.DataFrame(b)
print(c)
b.plot(x='ylevel', y='average')
print(b)
Posted
Updated 7-Dec-22 3:17am

1 solution

That is correct, a Python dictionary does not have a plot function. I gave you a link to the documentation for matplotlib yesterday, so go there again and look at the tutorials and examples, which explain how to do it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900