在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
optionsparameter. This is how thepivot_uifunction expects to receive pivottable.js-specific configurations. - Changing
colstocolumnsdidn't work because you were still passing it as a top-level argument instead of wrapping it inoptions—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
相关产品推荐
相关产品推荐

