ENH: add functions for aggregations
See original GitHub issueThe more I use Altair, the more the string aggregation shortcuts feel awkward to me.
I would propose we add an alternate syntax for creating aggregates based on top-level altair functions, and also add a top-level bin()
function as a shortcut to binning.
For example, instead of
chart.encode(
x=alt.X('x', bin=alt.Bin(maxbins=20)),
y='mean(y):Q'
)
we could instead have a syntax like this:
chart.encode(
x=alt.bin('x', maxbins=20),
y=alt.mean('y', 'Q')
)
The downside is that this is another step away from the user directly touching the structure of the spec, and might encourage a wrong mental map that may lead to other confusions. To some degree, though, that is already an issue with the current string-based shortcuts.
The upside is that it is much more natural in Python to use actual functions for these functions rather than writing them out in strings.
@elisonbg @kanitw @domoritz I’d love to hear your thoughts on this. If they’re generally positive, I can work on an implementation (there will be a couple subtleties, but it shouldn’t be too bad).
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:23 (13 by maintainers)
Top GitHub Comments
This is already the case when data is passed as a dataframe
This is how I would see that. The old way:
The new way:
But since aggregations are almost always quantitative, it would actually be this:
The alternative notation is not a conceptual break from the old notation… it just removes the need to embed function calls within strings.