Facing an issue while creating the pivot table using Pandas with Data frames. tried with xlwings , but getting different error regarding number format

huangapple go评论71阅读模式
英文:

Facing an issue while creating the pivot table using Pandas with Data frames. tried with xlwings , but getting different error regarding number format

问题

我的目标是使用Python创建以下格式的数据透视表。

Facing an issue while creating the pivot table using Pandas with Data frames. tried with xlwings , but getting different error regarding number format

我们需要按照上述层次结构创建数据透视表。我尝试过使用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.

Facing an issue while creating the pivot table using Pandas with Data frames. tried with xlwings , but getting different error regarding number format.

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=[&#39;ROC | Channel Type&#39;, &#39;Revised Request Type&#39;, &#39;Reference Number&#39;, &#39;ROC | Country name&#39;], values=[&#39;Pre Production Actual&#39;, &#39;Pre-Prod Target Tat&#39;])`

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, &#39;Exception occurred.&#39;, (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.

Facing an issue while creating the pivot table using Pandas with Data frames. tried with xlwings , but getting different error regarding number format

答案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 = [[&#39;Pre Production Actual&#39;, &#39;Pre Production Actual&#39;, win32c.xlSum, &#39;0&#39;], [&#39;Pre-Prod Target Tat&#39;, &#39;Pre-Prod Target Tat&#39;, win32c.xlSum, &#39;0&#39;]] While providing values, we need to give different names for source and target fields. pt_fields = [[&#39;Pre Production Actual&#39;, &#39; sum Pre Production Actual&#39;, win32c.xlSum, &#39;0&#39;], [&#39;Pre-Prod Target Tat&#39;, &#39;sum Pre-Prod Target Tat&#39;, win32c.xlSum, &#39;0&#39;]]. This change filxed my issue.

huangapple
  • 本文由 发表于 2023年6月8日 23:34:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433521.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定