Reputation: 15
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
Upvotes: 0
Views: 235
Reputation: 822
If you don't need fancy formatting for your file, you can create a csv file (which can be opened in applications other than Microsoft Excel)
pandas
can do the job:
import pandas
csv_str = pandas.DataFrame(myDict).to_csv()
print(csv_str)
You can write the string to a file, or give a file path parameter to to_csv
:
csv_str = pandas.DataFrame(myDict).to_csv('file.csv')
Upvotes: 0
Reputation: 23146
Use pandas.to_excel()
:
import pandas as pd
pd.DataFrame(myDict).to_excel("file.xlsx")
Upvotes: 1