Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

I am facing difficulty in writing a nested dictionary to a CSV file. Below is the dictionary: 

Score = {'Student-1': {'1st Term': 0, '2nd Term': 0, '3rd Term': 0, '4th Term': 0}, 'ge60le90': {'1st Term': 4, '2nd Term': 0, '3rd Term': 0, '4th Term': 0}, 'gt90': {'1st Term': 0, '2nd Term': 1, '3rd Term': 2, '4th Term': 1} } 

I want to write this dictionary in a CSV format.

1 Answer

0 votes
by (25.1k points)

You can use pandas:

df = pd.DataFrame(Score)

df = df.rename(columns={'Student-1': 'Good',

'Student-2': 'Medium',

'Student-3': 'Bad'})

df.to_csv('student.csv', index=False)

If you want to get a deeper understanding of python you can watch this youtube video: 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 30, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

Browse Categories

...