Altair: DOC: It would be cool to have an example of calculating a cumulative sum on a time series

Created on 21 Jun 2018  Â·  5Comments  Â·  Source: altair-viz/altair

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.

Most helpful comment

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

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

visualization 17

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nielsmde picture nielsmde  Â·  4Comments

SuperShinyEyes picture SuperShinyEyes  Â·  3Comments

HalukaMB picture HalukaMB  Â·  3Comments

dzonimn picture dzonimn  Â·  3Comments

morberg picture morberg  Â·  3Comments