Writing to CSV and other delimited files
In this recipe, you will export a DataFrame as a CSV file and leverage the different parameters in the DataFrame.to_csv()
writer function.
Getting ready
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 you will be working with is named movieboxoffice.csv
which you read first to create your DataFrame.
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 = Path('../../datasets/Ch4/movieboxoffice.csv')
movies = pd.read_csv(filepath,
header=0,
parse_dates=[0],
index_col=0,
usecols=['Date',
'Daily'],
date_format="%d-%b-%y")
movies.info()
>>
<class 'pandas.core.frame.DataFrame...