PANDAS DATAFRAMES AND EXCEL SPREADSHEETS
Listing 3.21 displays the contents of write_people_xlsx.py that illustrates how to read data from a CSV file and then create an Excel spreadsheet with that data.
LISTING 3.21: write_people_xlsx.py
import pandas as pd
df1 = pd.read_csv("people.csv")
df1.to_excel("people.xlsx")
#optionally specify the sheet name:
#df1.to_excel("people.xlsx", sheet_name='Sheet_name_1')
Listing 3.21 initializes the Pandas DataFrame df1 with the contents of the CSV file people.csv, and then invokes the to_excel() method in order to save the contents of the DataFrame to the Excel spreadsheet people.xlsx.
Listing 3.22 displays the contents of read_people_xlsx.py that illustrates how to read data from the Excel spreadsheet people.xlsx and create a Pandas DataFrame with that data.
LISTING 3.22: read_people_xlsx.py
import pandas as pd
df = pd.read_excel("people.xlsx")
print("Contents of Excel spreadsheet:"...