Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
change to loop
#1
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
Reply
#2
Without "grades.csv", it is difficult to help.
Reply
#3
link to grades:
Reply
#4
Your link does not work for me.
And I can not read that language.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Change the varaible in For Loop quest 2 1,715 Aug-13-2021, 03:35 PM
Last Post: deanhystad
  Change variable value during a while loop? penahuse 2 4,050 Nov-15-2020, 11:53 PM
Last Post: penahuse
  (Python help) Change in logic not breaking 'while' loop? btcg2807 1 1,889 Sep-18-2019, 09:43 AM
Last Post: Larz60+
  change array column values without loop khalidreemy 2 3,766 May-05-2019, 09:05 AM
Last Post: DeaD_EyE
  Code Change Help: Infinite Loop Error bindulam 2 2,245 Mar-10-2019, 11:15 PM
Last Post: hshivaraj
  How to change from printFacts ( ) to return a list & Loop over list when writing CSV Ivan1 14 8,285 Aug-30-2017, 12:14 PM
Last Post: metulburr
  Timestamp doesn't change with each loop lwhistler 2 6,754 Aug-23-2017, 06:58 PM
Last Post: bowen73
  Loop thru textfile, change 3 variables for every line herbertioz 11 9,115 Nov-10-2016, 04:56 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020