nicolaskruchten / jupyter_pivottablejs

Drag’n’drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js
http://nicolas.kruchten.com/content/2015/09/jupyter_pivottablejs/
Other
687 stars 88 forks source link

derived attributes? #45

Closed jeffbryner closed 6 years ago

jeffbryner commented 6 years ago

I think it supports derived attributes, but it's not clear (to me) how to make it go ;-]

Trying:

from pivottablejs import pivot_ui
import pivottablejs

pivot_ui(df,      
    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'
        }}}
    },
 derivedAttributes= {
                    "Age Bin": "$.pivotUtilities.derivers.bin('Age', 10)"
        }
)

yields "An error occurred rendering the PivotTable UI." and the html source says:

"derivedAttributes": {"Age Bin": "$.pivotUtilities.derivers.bin('Age', 10)"}})
                ).show();

which obviously isn't right.

Any clues?

nicolaskruchten commented 6 years ago

Unfortunately you can only use JSON serializable options here, not functions. This means no derived attributes and no sorters...

https://github.com/PierreMarion23/ipypivot has somewhat better support though!

On Sat, Oct 6, 2018 at 13:46 Jeff Bryner notifications@github.com wrote:

I think it supports derived attributes, but it's not clear (to me) how to make it go ;-]

Trying:

from pivottablejs import pivot_ui import pivottablejs

pivot_ui(df, 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' }}} }, derivedAttributes= { "Age Bin": "$.pivotUtilities.derivers.bin('Age', 10)" } )

yields "An error occurred rendering the PivotTable UI." and the html source says:

"derivedAttributes": {"Age Bin": "$.pivotUtilities.derivers.bin('Age', 10)"}}) ).show();

which obviously isn't right.

Any clues?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nicolaskruchten/jupyter_pivottablejs/issues/45, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMbAxFHj7ZcECFkVEakDbrov0L_aUp-ks5uiOyCgaJpZM4XLd5k .

jeffbryner commented 6 years ago

ahh, I see thanks!