Zhang
0
Q:

dataframe to dictionary using index as key

df.to_dict('records')
0
#Use the Dataframe index as the key of the dictionary
df.to_dict('index')
0
{'Name': ['John', 'Sara', 'John', 'Sara'],
 'Sem': ['Sem1', 'Sem1', 'Sem2', 'Sem2'],
 'Subject': ['Mathematics', 'Biology', 'Biology', 'Mathematics'],
 'Grade': ['A', 'B', 'A+', 'B++']}
0

New to Communities?

Join the community