Skip to content
Advertisement

Nested dictionary to CSV convertion optimization

I have a dictionary like this:

JavaScript

My function to transform that into a CSV is this one:

JavaScript

My output is a csv file like this:

enter image description here

It is working, but it isn’t well optimized. The process is very slow when I run into a dictionary with more than > 10,000 entries. Any ideas on how to speed this process up? Thank you for your time.

Advertisement

Answer

I’d start with getting rid of pandas.append. Appending rows to DataFrames is inefficient. You can create a DataFrame in one go:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement