英文:
Facing an issue while creating the pivot table using Pandas with Data frames. tried with xlwings , but getting different error regarding number format
问题
我的目标是使用Python创建以下格式的数据透视表。
我们需要按照上述层次结构创建数据透视表。我尝试过使用Pandas
的以下代码,但没有找到重新创建所需层次结构的解决方案。
df = pd.pivot_table(df, index=['ROC | Channel Type', 'Revised Request Type', 'Reference Number', 'ROC | Country name'], values=['Pre Production Actual', 'Pre-Prod Target Tat'])
我还尝试了使用xlwings,参考使用Python自动化Excel数据透视表,但出现了“数字格式”问题。我尝试使用了所有这些数字格式Excel数字格式,但没有帮助。
错误信息如下:
line 32077, in AddDataField
ret = self._oleobj_.InvokeTypes(2122, LCID, 1, (9, 0), ((9, 1), (12, 17), (12, 17)),Field
pywintypes.com_error: (-2147352567, '发生异常。', (0, None, None, None, 0, -2146827284), None)
我的目标是使用Python添加多行和值来创建表格。如果我需要更新什么,请告诉我。
英文:
My goal is to create Pivot table in the below format using Python.
We need to create pivot table in above hierarchy. I tried the below code using Pandas
, but didn't find any solution to recreate the required hierarchy. <br>
Code for reference below;
`df = pd.pivot_table(df, index=['ROC | Channel Type', 'Revised Request Type', 'Reference Number', 'ROC | Country name'], values=['Pre Production Actual', 'Pre-Prod Target Tat'])`
I used xlwings as well using Automate Excel with Python Pivot Table, but I'm getting Number Format
issues. I tried using all these number formats Excel Number Formats, but this didn't help.<br>
<br>
Error text for reference;<br>
line 32077, in AddDataField
ret = self._oleobj_.InvokeTypes(2122, LCID, 1, (9, 0), ((9, 1), (12, 17), (12, 17)),Field
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146827284), None)
My goal is to create table by adding multiple rows and values using Python.<br>
Please let me know If I want to update anything here.
答案1
得分: 0
Issue fixed. pt_fields = [['Pre Production Actual', 'Pre Production Actual', win32c.xlSum, '0'], ['Pre-Prod Target Tat', 'Pre-Prod Target Tat', win32c.xlSum, '0']]
While providing values, we need to give different names for source and target fields. pt_fields = [['Pre Production Actual', ' sum Pre Production Actual', win32c.xlSum, '0'], ['Pre-Prod Target Tat', 'sum Pre-Prod Target Tat', win32c.xlSum, '0']]
. This change fixed my issue.
英文:
Issue fixed. pt_fields = [['Pre Production Actual', 'Pre Production Actual', win32c.xlSum, '0'], ['Pre-Prod Target Tat', 'Pre-Prod Target Tat', win32c.xlSum, '0']]
While providing values, we need to give different names for source and target fields. pt_fields = [['Pre Production Actual', ' sum Pre Production Actual', win32c.xlSum, '0'], ['Pre-Prod Target Tat', 'sum Pre-Prod Target Tat', win32c.xlSum, '0']]
. This change filxed my issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论