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 them in a excel sheet as follows
number of storage arrays 45
number of ports 2390
I have a very big dictionary.
In the explorer, open the dictionary. Click Import / Export > Export Excel. The option Export the entire dictionary is selected by default.
to_excel() Function in Python. If we want to write tabular data to an Excel sheet in Python, we can use the to_excel() function in Pandas DataFrame . A pandas DataFrame is a data structure that stores tabular data. The to_excel() function takes two input parameters: the file's name and the sheet's name.
In Python to convert a dictionary to CSV use the dictwriter() method. This method is used to insert data into the CSV file. In Python, the CSV module stores the dictwriter() method. It creates an object and works like the dictwriter().
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
with open('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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With