-
I generated this using a bunch of custom pandas pivot/melt/cumsum logic: I'd like to use altair transforms instead, but I don't quite understand how to do so. I tried repurposing this but got lost. Is there another/better place to look for docs/examples of what I'm trying to accomplish? Happy to try and contribute some update examples if that would be helpful. |
Beta Was this translation helpful? Give feedback.
Answered by
jakevdp
Dec 14, 2021
Replies: 1 comment 3 replies
-
It should look pretty much exactly like the example you linked to, except with a import pandas as pd
import altair as alt
data = pd.DataFrame({
'qtr': ['2016Q1', '2016Q2', '2016Q3', '2016Q4', '2017Q1', '2017Q2', '2017Q3', '2017Q4',
'2016Q1', '2016Q2', '2016Q3', '2016Q4', '2017Q1', '2017Q2', '2017Q3', '2017Q4'],
'company': ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',
'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B'],
'value': [5, 4, 5, 6, 4, 7, 8, 3,
7, 8, 8, 9, 6, 5, 8, 7],
})
alt.Chart(data).transform_window(
cumulative='sum(value)',
sort=[{"field": "qtr"}],
groupby=['company'],
).mark_line().encode(
x='qtr:N',
y='cumulative:Q',
color='company:N',
) |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
jimmywan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It should look pretty much exactly like the example you linked to, except with a
groupby
in the window transform and an additionalcolor
encoding. Here's a short example: