Python-Excel Integration Flashcards
1
Q
Push with openpyxl
A
Refresh values
import openpyxl
wb = openpyxl.load_workbook(‘Quarterly_Financials.xlsx’)
wb[‘Sheet1’][‘B2’] = 35531
wb[‘Sheet1’][‘B3’] = 25729
wb[‘Sheet1’].append([24331])
wb.save(‘Updated_Financials.xlsx’)
print(“Financial report updated!”)
2
Q
Pull with pandas
A
Load specific sheet by index/name
import pandas as pd
dfs = pd.read_excel(‘SalesData.xlsx’, sheet_name=’WestCoast’)
west_sales = dfs[dfs[‘Region’]==’West’]
totals = west_sales.groupby(‘Rep’).Amount.sum()
totals.to_excel(‘WestCoast_Totals.xlsx’)