{ "info": { "author": "Jake VanderPlas", "author_email": "jakevdp@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Console", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3.7" ], "description": "# altair-transform\n\nPython evaluation of Altair/Vega-Lite transforms.\n\n[](https://travis-ci.org/altair-viz/altair-transform)\n\n## Example\n\nThe Vega-Lite specification includes the ability to apply a\nwide range of transformations to input data within the chart\nspecification. As an example, here is a sliding window average\nof a Gaussian random walk, implemented in Altair:\n\n```python\nimport altair as alt\nimport numpy as np\nimport pandas as pd\n\nrand = np.random.RandomState(12345)\n\ndf = pd.DataFrame({\n 'x': np.arange(200),\n 'y': rand.randn(200).cumsum()\n})\n\npoints = alt.Chart(df).mark_point().encode(\n x='x:Q',\n y='y:Q'\n)\n\nline = alt.Chart(df).transform_window(\n ymean='mean(y)',\n sort=[alt.SortField('x')],\n frame=[5, 5]\n).mark_line(color='red').encode(\n x='x:Q',\n y='ymean:Q'\n)\n\npoints + line\n```\n\n\nBecause the transform is encoded within the renderer, however, it\nis not easy from Altair to access the computed values.\n\nThis is where ``altair_transform`` comes in. It includes a (nearly)\ncomplete Python implementation of Vega-Lite's transform layer, so\nthat you can easily extract a pandas dataframe with the computed\nvalues shown in the chart:\n\n```python\nfrom altair_transform import extract_data\ndata = extract_data(line)\ndata.head()\n```\n
| \n | x | \ny | \nymean | \n
|---|---|---|---|
| 0 | \n0 | \n-0.204708 | \n0.457749 | \n
| 1 | \n1 | \n0.274236 | \n0.771093 | \n
| 2 | \n2 | \n-0.245203 | \n1.041320 | \n
| 3 | \n3 | \n-0.800933 | \n1.336943 | \n
| 4 | \n4 | \n1.164847 | \n1.698085 | \n