Skip to content Skip to sidebar Skip to footer

Export A Simple Dictionary Into Excel File In Python

I am new to python. I have a simple dictionary for which the key and values are as follows dict1 = {'number of storage arrays': 45, 'number of ports':2390,......} i need to get th

Solution 1:

You can use pandas.

import pandas as pd

dict1 = {"number of storage arrays": 45, "number of ports":2390}

df = pd.DataFrame(data=dict1, index=[0])

df = (df.T)

print (df)

df.to_excel('dict1.xlsx')

Solution 2:

Sassikant,

This will open a file named output.csv and output the contents of your dictionary into a spreadsheet. The first column will have the key, the second the value.

import csv

withopen('output.csv', 'wb') as output:
    writer = csv.writer(output)
    for key, value in dict1.iteritems():
        writer.writerow([key, value])

You can open the csv with excel and save it to any format you'd like.

Post a Comment for "Export A Simple Dictionary Into Excel File In Python"