You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Jupyter Notebook中复现pivottable.js示例时遇pivot_ui参数错误求助

Fixing the TypeError with pivot_ui() in Jupyter Notebook

Hey there, let's sort out this error you're hitting! The TypeError: pivot_ui() got an unexpected keyword argument 'cols' happens because parameters like cols, rows, etc., aren't direct arguments for the pivot_ui() function—they're actually configuration options for pivottable.js itself, and need to be passed inside an options dictionary.

Corrected Code

from pivottablejs import pivot_ui

pivot_ui(
    df,
    options={
        "cols": ["Party"],
        "rows": ["Province"],
        "rendererName": "Horizontal Stacked Bar Chart",
        "rowOrder": "value_z_to_a",
        "colOrder": "value_z_to_a",
        "rendererOptions": {
            "c3": {
                "data": {
                    "colors": {
                        "Liberal": '#dc3912',
                        "Conservative": '#3366cc',
                        "NDP": '#ff9900',
                        "Green": '#109618',
                        'Bloc Quebecois': '#990099'
                    }
                }
            }
        }
    }
)

What Changed & Why

  • All the settings you wanted to apply (like column/row selections, chart type, color coding) are now nested inside the options parameter. This is how the pivot_ui function expects to receive pivottable.js-specific configurations.
  • Changing cols to columns didn't work because you were still passing it as a top-level argument instead of wrapping it in options—the function doesn't recognize any of these as direct inputs.

Once you run this adjusted code, it should correctly pass your preferences to pivottable.js and generate the horizontal stacked bar chart you're aiming for.

内容的提问来源于stack exchange,提问作者Sandra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:32:52