我需要將用數據框制作的數據透視表放在 googlesheet 中。當我嘗試在 jupyter 中運行它時,它應該顯示:但是當我將數據導出到 googlesheet 時,索引標題丟失,如下圖所示:這是我的代碼的一部分,負責創建數據框并將其導出到 googlesheet 中。我正在使用 pygsheets 庫來訪問 googlesheets。df1 = wks.get_as_df()df1 = df1.apply(pd.to_numeric, errors='ignore')df2 = pd.pivot_table(df1, index =['SSPU','Color'], columns = "Size",values='US 全庫存',fill_value=0, aggfunc = sum, margins=True)print(df2)我檢查了很多教程,但沒有找到解決方案。
1 回答

三國紛爭
TA貢獻1804條經驗 獲得超7個贊
對于set_dataframe()
寫入 google 工作表的功能,請根據文檔設置copy_index=True
默認值。copy_index=False
我以前從未使用過這個庫,但希望它對你有用。
set_dataframe(df, start, copy_index=False, copy_head=True, extend=False, fit=False, escape_formulae=False, **kwargs)
https://pygsheets.readthedocs.io/en/stable/worksheet.html
參數:
copy_index – 復制數據幀索引(支持多索引)。
添加回答
舉報
0/150
提交
取消