Skip to content
Advertisement

How to create a custom CSV file from Python dictionary?

I want to create a CSV file like this:

JavaScript

But I get this:

JavaScript

The code I wrote:

JavaScript

What should I do?

Advertisement

Answer

You would need to first transform your data according to the expected structure

JavaScript

Once you do that you could use pandas to save it as CSV like so :

JavaScript

The resulting csv :

JavaScript
Advertisement