Excel Files
Microsoft Excel is ubiquitous. We use Excel to store data on customers, inventory, and employees. We use it to track operations, sales, and financials. The list of ways people use Excel in business is long and diverse. Because Excel is such an integral tool in business, knowing how to process Excel files in Python will enable you to add Python into your data processing workflows, receiving data from other people and sharing results with them in ways theyâre comfortable with.
Unlike Pythonâs csv
module, there is not a standard module in Python for processing Excel files (i.e., files with the .xls or .xlsx extension). To complete the examples in this section, you need to have the xlrd
and xlwt
packages. The xlrd
and xlwt
packages enable Python to process Excel files on any operating system, and they have strong support for Excel dates. If you installed Anaconda Python, then you already have the packages because theyâre bundled into the installation.Â
A few words on terminology: when I refer to an âExcel fileâ thatâs the same thing as an âExcel workbook.â An Excel workbook contains one or more Excel worksheets. In this lesson, Iâll be using the words âfileâ and âworkbookâ interchangeably, and Iâll refer to the individual worksheets within a workbook as worksheets.
Weâll go through each of the examples here in base Python, so you can see every logical step in the data processing, and then using pandas, so you can have a (usually) shorter ...
Get Working with Excel files in Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.