Writing data to an Excel file
In this recipe, you will export a DataFrame as an Excel file format and leverage the different parameters available in the DataFrame.to_excel()
writer function.
Getting ready
In the Reading data from an Excel file recipe in Chapter 2, Reading Time Series Data from Files, you had to install openpyxl
as the engine for reading Excel files with pandas.read_excel()
. For this recipe, you will use the same openpyxl
as the engine for writing Excel files with DataFrame.to_excel()
.
To install openpyxl
using conda
, run the following:
>>> conda install openpyxl
You can also use pip
:
>>> pip install openpyxl
The file is provided in the GitHub repository for this book, which you can find here: https://github.com/PacktPublishing/Time-Series-Analysis-with-Python-Cookbook. The file is named movieboxoffice.csv
.
To prepare for this recipe, you will read the file into a DataFrame with the following code:
import pandas as pd
from pathlib import Path
filepath...