Skip to content
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

Closed
palewire opened this issue Jun 21, 2018 · 5 comments

Comments

@palewire
Copy link
Contributor

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.

@jakevdp
Copy link
Collaborator

jakevdp commented Jun 21, 2018

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...

@jakevdp
Copy link
Collaborator

jakevdp commented Jun 21, 2018

I took a stab at cleaning-up the window syntax; see #957

@jakevdp
Copy link
Collaborator

jakevdp commented Jun 21, 2018

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]
)

visualization 17

@palewire
Copy link
Contributor Author

I like that as a goal! The one I drafted this morning, which prompted me to file this ticket, is gnarly in comparison.

@jakevdp
Copy link
Collaborator

jakevdp commented May 26, 2019

We have relevant examples in the docs now at https://altair-viz.github.io/user_guide/transform.html#window-transform

@jakevdp jakevdp closed this as completed May 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants