Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何重新排序和重命名数据透视? 我正在尝试对导出到excel的列重新排序。它目前是按字母顺序排列的。我要销售订单净值、账单净值和未结金额 是否有方法仅为excel重命名列 如何将底部的All重命名为Grand Total_Python_Python 3.x_Pandas - Fatal编程技术网

Python 如何重新排序和重命名数据透视? 我正在尝试对导出到excel的列重新排序。它目前是按字母顺序排列的。我要销售订单净值、账单净值和未结金额 是否有方法仅为excel重命名列 如何将底部的All重命名为Grand Total

Python 如何重新排序和重命名数据透视? 我正在尝试对导出到excel的列重新排序。它目前是按字母顺序排列的。我要销售订单净值、账单净值和未结金额 是否有方法仅为excel重命名列 如何将底部的All重命名为Grand Total,python,python-3.x,pandas,Python,Python 3.x,Pandas,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=['C

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']
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']