admin管理员组文章数量:1244316
I've made the following column:
df_base['CustomerDaysInterval'] = pd.cut(x=df_base['CustomerDays'],
bins=[0,15,30,45,60,75,90],
labels= ["0 to 15 days","15 to 30 days", "30 to 45 days", "45 to 60 days","60 to 75 days","75 to 90 days"])
After that, i'm having an issue when adding parameters margins=True:
df_pivot = pd.pivot_table(
data=df_base.reset_index(),
index= 'Sales Team',
columns='CustomerDaysInterval',
aggfunc='size',
observed=True,
margins=True).reset_index()
With the above code I get a KeyError: '0 to 15 days'. It should be noted that by removing the margins=True parameter, the code works properly.
本文标签: pythonpdpivot table issue when adding marginsTrueStack Overflow
版权声明:本文标题:python - pd.pivot table issue when adding margins=True - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740201789a2240350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论