Using Excel files
While CSV files are common, it seems that the world is ruled by Excel. I've been surprised in my consulting work to see how many companies are using Excel as a critical if not the critical tool for making decisions.
In this recipe, we will show how to create and read Excel files. You may need to install xlwt or openpyxl to write XLS or XLSX files, respectively.
How to do it...
- Create an Excel file using the
.to_excelmethod. You can write eitherxlsfiles orxlsxfiles:>>> beatles.to_excel("beat.xls") >>> beatles.to_excel("beat.xlsx")
Excel file
- Read the Excel file with the
read_excelfunction:>>> beat2 = pd.read_excel("/tmp/beat.xls") >>> beat2 Unnamed: 0 first last birth 0 0 Paul McCartney 1942 1 1 John Lennon 1940 2 2 Richard Starkey 1940 3 3 ...