Is there a way to create a custom aggregator for pivot_ui in python? I'd like to do weighted averages and hide the details of the computation/field-mappings from users, and only provide meaningful labels in the custom aggregator dropdown. All examples of custom aggregators are in javascript. Is there a way to do it in python/jupyter?
eg. in javascript: ( from view-source:http://horner.github.io/pivottable/examples/montreal_2014.html )
$(function () {
var tpl = $.pivotUtilities.aggregatorTemplates;
$.get("montreal_2014.csv", function(montreal_2014) {
$("#output").pivotUI($.csv.toArrays(montreal_2014), {
aggregators: {
"Mean Temp (Celcius)":
function() { return tpl.average()(["Mean Temp (C)"])},
in python:
from pivottablejs import pivot_ui
pivot_ui( df, rows=["day"], aggregators= ?? )
How do I define and pass a javascript function obj in jupyter notebook? could I somehow define it with %%javascript in a different cell and reference in python? or is there some magic in the streamlit.components.v1 that can accomplish this?
thanks
Looking at the pivottablejs library for Python, it looks like they return an IFrame. You can try components.html form Streamlit
import streamlit as st
import streamlit.components.v1 as components
from pivottablejs import pivot_ui
import pandas as pd
t = pivot_ui(df)
with open(t.src) as t:
components.html(t.read(), width=900, height=1000, scrolling=True)