For more information about concepts covered in this lesson, you can check out:
Reading and Writing Excel Files
Reading and writing Excel files. Microsoft Excel is probably the most widely-used spreadsheet software. While older versions use binary
.xls files, Excel 2007 introduced the new XML-based
You can read and write Excel files in pandas similar to CSV files. However, you’ll need to install the following Python packages first:
xlwt to write to
XlsxWriter to write to
xlrd to read Excel files.
Please note that you don’t have to install all these packages, although doing so will allow you to get started with a minimum of fuss. For example, you don’t need both
XlsxWriter, and if you’re only ever going to write
.xlsx files, then you may want to just use
01:14 If you’re only going to work with the older binary Excel files, then you’ll want to use the appropriate packages depending on if you’ll be reading, writing, or both. Take some time to decide which packages are right for your project, and if you’re deploying an application, then only install the packages you’ll actually be using.
'data.xlsx' represents the target file and, optionally, its path. The statement you see onscreen should create the file
data.xlsx in your current working directory. Opening it up in Excel, it should look like this.
02:45 You can also check out Using Pandas to Read Large Excel Files in Python. In the next section of the course, you’ll take a deeper look at how pandas interacts with files, and work with more file types.
Become a Member to join the conversation.