Iβm currently using Plotly Express (Open to using Plotly) and trying to build a treemap that renders % (Percentages) for the value but trying to understand how to handle this for the parents/path in the data.
Consider a dataframe as follows:
| parent_1 | parent_2 | metric_1_numerator | metric_2_denominator | p_metric |
| --------- | --------- | -------------------- | ---------------------- | --------- |
| A | A.1 | 10 | 20 | .5 |
| A | A.2 | 5 | 25 | .2 |
| B | B.1 | 10 | 100 | .1 |
To use a treemap I would have a path that would go parent_1 β parent_2. Ultimately the value I want to render is metric_1_numerator
/ metric_2_denominator
. However, the edge case is that when I am at parent_1 the underlying data needs to be summed SUM(metric_1_numerator
) / SUM(metric_2_denominator
). Thus the value aggregated for Parent_1 would be:
A: SUM(10+5) / SUM(20+25) = .333
B: SUM(10) / SUM(100) = .1
The values
argument for px.treemap (plotly.express.treemap β 5.18.0 documentation) says:
So Iβm not sure how to make use of it here.
Any insight on how to handle this?
Thanks -