I have some data that I'd like to save in an excel file. How does one do this in python?
There's a great python module called XLWT. I'd recommend using that... it writes native Excel files instead of CSVs. Supports formulas, etc too.
Documentation (borrowed from Mark)
I'll answer a slightly different question: "How can I write data so that Excel can read it?"
Use the csv
module to write your data as a .csv file, and then open it in Excel.
import csv
csvout = csv.writer(open("mydata.csv", "wb"))
csvout.writerow(("Country", "Year"))
for coutry, year in my_data_iterable():
csvout.writerow((country, year))
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