Tengo una dataframe que representa los id y nombres de estudiantes. Quiero hacer una matriz de objetos-estudiantes. Sin embargo obtengo ValueError: too many values to unpack (expected 2)
.
Mi intento:
main.py
# main
import pandas
from student import Student
if __name__ == "__main__":
# execute only if run as a script
students_df = pandas.read_csv("students.csv")
students = []
print(students_df[['id','name']])
for id,name in students_df[['id','name']]:
print(id, name)
students.append(Student(id,name))
print(students)
student.py
# student
class Student:
def __init__(self, id, name):
self.id = id
self.name = name
self.courses=[]
def addCourse(self,course_id):
self.courses.append(course_id)
mensaje de error.
(backenv) C:\Users\antoi\Documents\Programming\Hatchways\backend-assessment>py main.py
id name
0 1 A
1 2 B
2 3 C
i d
[<student.Student object at 0x0000014FF8C7C4A8>]
Traceback (most recent call last):
File "main.py", line 25, in <module>
for id,name in students_df[['id','name']]:
ValueError: too many values to unpack (expected 2)
Además me parece extraño que el primero print devuelve i d
Data
El archivo student.csv está aquí.