-
Notifications
You must be signed in to change notification settings - Fork 786
-
Notifications
You must be signed in to change notification settings - Fork 786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: It would be cool to have an example of calculating a cumulative sum on a time series #956
Comments
Sounds good – you could probably do something similar to this vega-lite example, but use a sum rather than a mean: https://vega.github.io/vega-lite/docs/window.html#cumulative-running-average The window transform syntax is still a bit awkward, so that's something we need to think about... |
I took a stab at cleaning-up the window syntax; see #957 |
Here's a toy example with the syntax of #957: import altair as alt
import pandas as pd
import numpy as np
data = pd.DataFrame({'date': pd.date_range('2018-01-01', periods=100, freq='D'),
'value': 0.3 + np.random.randn(100)})
alt.Chart(data).mark_line().encode(
x='date:T',
y='cuml:Q'
).transform_window(
cuml='sum(value)',
frame=[None, 0]
) |
I like that as a goal! The one I drafted this morning, which prompted me to file this ticket, is gnarly in comparison. |
We have relevant examples in the docs now at https://altair-viz.github.io/user_guide/transform.html#window-transform |
I suspect one of the most frequent usage of the window transformation will be to calculating running cumulative tallies over a time series.
The only example in the docs right now that I can find does a percentage of total calculation. That is also useful, but we should cover this other use case as well. The Wikipedia donations case study is cool, but the "year to date" totals are pre-calculated so it's not useful for demonstrating this feature.
If you can explain me to me how to write the code, I'd be happy to craft a good example.
The text was updated successfully, but these errors were encountered: