Python Forum

Full Version: change to loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I wrote this code that takes info (grades and student names) from a csv file with pandas and make a graph with matplotlib.

import pandas as pd import matplotlib.pyplot as plt grd = pd.read_csv("grades.csv") print(grd) x = grd.columns[1:] y1 = grd.loc[0,'YearA':] y2 = grd.loc[1,'YearA':] y3 = grd.loc[2,'YearA':] y4 = grd.loc[3,'YearA':] y5 = grd.loc[4,'YearA':] plt.plot(x, y1, x ,y2, x, y3, x, y4, x, y5) plt.legend(grd.Student) plt.show()
I want to change this code to a loop and not to put each student separately (now i have 5, but what if i'll have 50?)
I tried so many ways,
pls help :)

Thanks Big Grin
Without "grades.csv", it is difficult to help.
Your link does not work for me.
And I can not read that language.