Search code examples
pythonexcelcsvdictionaryxlsx

how to export nested dict into excel file?


my dict:

myDict = {0: {'max': 30,
              'min': 10},
          1: {'max': 40,
              'min': 25}
          }

How can I get this into an excel file looking like this:

        0        1
max    30       40
min    10       25

Solution

  • Use pandas.to_excel():

    import pandas as pd
    pd.DataFrame(myDict).to_excel("file.xlsx")