Working With Excel Files
Working with Excel files. You’ve already learned how to read and write Excel files with pandas. However, there are a few more options worth considering. For one, when you use
.to_excel(), you can specify the name of the target worksheet with the optional parameter
Here, you create a file with a worksheet called
COUNTRIES that stores the data. The optional parameters
startcol both default to
0 and indicate the upper-leftmost cell where the data should start being written into the Excel spreadsheet.
Here, you specify that the table should start in the third row and the fifth column. Remember, you’re using zero-based indexing, so the third row is denoted by
2 and the fifth column by
Here’s what the resulting worksheet looks like.
read_excel() also has the optional parameter
sheet_name that specifies which worksheets to read when loading data.
It can take one of the following values: the zero-based index of the worksheet, the name of the worksheet, a list of indices or names to read multiple sheets, and the value
None to read all sheets.
01:43 Here’s an example of how you’d use this parameter.
parse_dates=['IND_DAY'] tells pandas to try to consider the values in this column as dates or times. There are other optional parameters you can use with
.to_excel() to determine the Excel engine, specify data types, specify the strings that will be interpreted by pandas as
nan values, and the parsing of dates, amongst others.
Become a Member to join the conversation.