0

I was plotting a graph using matplotlib for a csv file.

The Y axis in the graph seems to be out of order. I have check the column. It is of int().

If I try to change y.append(row[1]) to y.append(int(row[1])) I am getting Value ErrorValueError: invalid literal for int() with base 10: 'Rating/total'

enter image description here

Below is the code

x = []
y = []

with open('Abhigyan_alternate_school.csv','r') as csvfile:
    lines = csv.reader(csvfile, delimiter=',')
    for row in lines:
        x.append(row[0])
        y.append(row[1])
  
plt.plot(x, y, color = 'g', linestyle = 'dashed',
         marker = 'o',label = "school ratings")
  
plt.xticks(rotation = 50)
plt.xlabel('school Name')
plt.ylabel('Rating/total')
plt.title('school ratings', fontsize = 20)
plt.grid()
plt.legend()
plt.show()
Anu
  • 13
  • 4
  • Well, your `csv` has a string value where you expect an integer. Maybe it is the first or second line in your file? – JohanC Dec 16 '22 at 22:37

0 Answers0