A Python package for offline access to Vega datasets
Archived. The repository is read-only: no more fixes or releases will come.
pip install vega-datasetsvega_datasets
A Python package for offline access to vega datasets.
This package has several goals:
- Provide straightforward access in Python to the datasets made available at vega-datasets.
- return the results in the form of a Pandas dataframe.
- wherever dataset size and/or license constraints make it possible, bundle the dataset with the package so that datasets can be loaded in the absence of a web connection.
Currently the package bundles a half-dozen datasets, and falls back to using HTTP requests for the others.
Installation
vega_datasets is compatible with Python 3.5 or newer. Install with:
$ pip install vega_datasets
Usage
The main object in this library is data:
>>> from vega_datasets import data
It contains attributes that access all available datasets, locally if available. For example, here is the well-known iris dataset:
>>> df = data.iris()
>>> df.head()
petalLength petalWidth sepalLength sepalWidth species
0 1.4 0.2 5.1 3.5 setosa
1 1.4 0.2 4.9 3.0 setosa
2 1.3 0.2 4.7 3.2 setosa
3 1.5 0.2 4.6 3.1 setosa
4 1.4 0.2 5.0 3.6 setosa
If you're curious about the source data, you can access the URL for any of the available datasets:
>>> data.iris.url
'https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/iris.json'