跳转到主要内容

Python包,用于离线访问Vega数据集

项目描述

vega_datasets

build status github actions github actions code style black

一个Python包,用于离线访问vega数据集

本包有几个目标

  • 为Python提供对vega-datasets GitHub存储库 中提供的数据集的简单访问。
  • 以Pandas数据框的形式返回结果。
  • 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.

目前该软件包捆绑了六个数据集,并回退到使用HTTP请求来获取其他数据集。

安装

vega_datasets 与Python 3.5或更高版本兼容。使用以下命令进行安装:

$ pip install vega_datasets

使用

此库中的主要对象是 data

>>> from vega_datasets import data

它包含访问所有可用数据集的属性,如果本地可用,则本地访问。例如,以下是著名的鸢尾花数据集

>>> 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

如果您对源数据感兴趣,可以访问任何可用数据集的URL

>>> data.iris.url
'https://cdn.jsdelivr.net.cn/npm/vega-datasets@v1.29.0/data/iris.json'

对于捆绑在软件包中的数据集,您还可以在磁盘上找到它们的位置

>>> data.iris.filepath
'/lib/python3.6/site-packages/vega_datasets/data/iris.json'

可用数据集

要列出所有可用数据集,请使用 list_datasets

>>> data.list_datasets()
['7zip', 'airports', 'anscombe', 'barley', 'birdstrikes', 'budget', 'budgets', 'burtin', 'cars', 'climate', 'co2-concentration', 'countries', 'crimea', 'disasters', 'driving', 'earthquakes', 'ffox', 'flare', 'flare-dependencies', 'flights-10k', 'flights-200k', 'flights-20k', 'flights-2k', 'flights-3m', 'flights-5k', 'flights-airport', 'gapminder', 'gapminder-health-income', 'gimp', 'github', 'graticule', 'income', 'iris', 'jobs', 'londonBoroughs', 'londonCentroids', 'londonTubeLines', 'lookup_groups', 'lookup_people', 'miserables', 'monarchs', 'movies', 'normal-2d', 'obesity', 'points', 'population', 'population_engineers_hurricanes', 'seattle-temps', 'seattle-weather', 'sf-temps', 'sp500', 'stocks', 'udistrict', 'unemployment', 'unemployment-across-industries', 'us-10m', 'us-employment', 'us-state-capitals', 'weather', 'weball26', 'wheat', 'world-110m', 'zipcodes']

要列出本地数据集(即捆绑在软件包中且无需网络连接即可使用的那些数据集),请使用 local_data 对象

>>> from vega_datasets import local_data
>>> local_data.list_datasets()

['airports', 'anscombe', 'barley', 'burtin', 'cars', 'crimea', 'driving', 'iowa-electricity', 'iris', 'seattle-temps', 'seattle-weather', 'sf-temps', 'stocks', 'us-employment', "wheat"]

我们计划在未来添加更多本地数据集,但需符合大小和许可约束。如果您想帮助此工作,请参阅 本地数据集问题

数据集信息

如果您想了解任何数据集的更多信息,请使用 description 属性

>>> data.iris.description
'This classic dataset contains lengths and widths of petals and sepals for 150 iris flowers, drawn from three species. It was introduced by R.A. Fisher in 1936 [1]_.'

此信息也是 data.iris 文档字符串的一部分。目前并非所有数据集都包含描述;我们希望在未来添加更多信息。

项目详情


下载文件

下载适用于您平台的应用程序。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。

源分发

vega_datasets-0.9.0.tar.gz (215.0 kB 查看哈希值)

上传

构建分发

vega_datasets-0.9.0-py3-none-any.whl (210.8 kB 查看哈希值)

上传 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面