All
重命名为Grand Total
?def create_sheet():
scriptfile = open('script.sql', 'r')
script = scriptfile.read()
df2 = pd.read_sql(script, my_connection)
df2 = df2.where((pd.notnull(df2)), None)
pivot = pd.pivot_table(df2,
index=['Customer_Name'],
values=[
'Billed_Net_Value',
'Sales_Order_Net_Value',
'Open_Amount'],
aggfunc=np.sum,
margins=True)
writer = pd.ExcelWriter('SAP.xlsx', engine='xlsxwriter')
pivot.to_excel(writer, sheet_name='Pivot')
workbook = writer.book
ws = writer.sheets['Pivot']
答案 0 :(得分:3)
def create_sheet():
scriptfile = open('script.sql', 'r')
script = scriptfile.read()
df2 = pd.read_sql(script, my_connection)
df2 = df2.where((pd.notnull(df2)), None)
pivot = pd.pivot_table(df2,
index=['Customer_Name'],
values=[
'Billed_Net_Value',
'Sales_Order_Net_Value',
'Open_Amount'],
aggfunc=np.sum,
margins=True)
col_order = ['Sales_Order_Net_Value', 'Billed_Net_Value', 'Open_Amount']
pivot = pivot[col_order].rename(index=dict(All='Grand Total'))
writer = pd.ExcelWriter('SAP.xlsx', engine='xlsxwriter')
pivot.to_excel(writer, sheet_name='Pivot')
workbook = writer.book
ws = writer.sheets['Pivot']