A python engine for evaluating Altair transforms.
Project description
altair-transform
Python evaluation of Altair/Vega-Lite transforms.
Example
The Vega-Lite specification includes the ability to apply a wide range of transformations to input data within the chart specification. As an example, here is a sliding window average of a Gaussian random walk, implemented in Altair:
import altair as alt
import numpy as np
import pandas as pd
rand = np.random.RandomState(12345)
df = pd.DataFrame({
'x': np.arange(200),
'y': rand.randn(200).cumsum()
})
points = alt.Chart(df).mark_point().encode(
x='x:Q',
y='y:Q'
)
line = alt.Chart(df).transform_window(
ymean='mean(y)',
sort=[alt.SortField('x')],
frame=[5, 5]
).mark_line(color='red').encode(
x='x:Q',
y='ymean:Q'
)
points + line
Because the transform is encoded within the renderer, however, it is not easy from Altair to access the computed values.
This is where altair_transform
comes in. It includes a (nearly)
complete Python implementation of Vega-Lite's transform layer, so
that you can easily extract a pandas dataframe with the computed
values shown in the chart:
from altair_transform import extract_data
data = extract_data(line)
data.head()
x | y | ymean | |
---|---|---|---|
0 | 0 | -0.204708 | 0.457749 |
1 | 1 | 0.274236 | 0.771093 |
2 | 2 | -0.245203 | 1.041320 |
3 | 3 | -0.800933 | 1.336943 |
4 | 4 | 1.164847 | 1.698085 |
From here, you can work with the transformed data directly in Python.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for altair_transform-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f861a864aceaf8347e197bddedb7343e5300064305e28ed8f5cc4ef57755a51 |
|
MD5 | b90571579f10d6dc8a153c9ff83d3cb9 |
|
BLAKE2b-256 | d576d45712f332c0cc0a1853195972fd92a82d37369986bdda9992b0a0e9c5a8 |