用于离线访问vega数据集的python包
vega_datasets的Python项目详细描述
织女星数据集
用于脱机访问vega datasets的python包。
此软件包有几个目标:
- 在python中提供对vega-datasets上提供的数据集的直接访问。
- 以pandas数据框的形式返回结果。
- 只要数据集大小和/或许可证约束允许,就可以将数据集与包捆绑在一起,以便在没有Web连接的情况下加载数据集。
目前,该包打包了六个数据集,并返回到对其他数据集使用http请求。
安装
$ pip install vega_datasets
用法
这个库中的主要对象是data
:
>>>fromvega_datasetsimportdata
它包含访问所有可用数据集的属性,如果 可用。例如,这里是著名的iris数据集:
>>>df=data.iris()>>>df.head()petalLengthpetalWidthsepalLengthsepalWidthspecies01.40.25.13.5setosa11.40.24.93.0setosa21.30.24.73.2setosa31.50.24.63.1setosa41.40.25.03.6setosa
如果您对源数据感兴趣,可以访问任何可用数据集的url:
>>>data.iris.url'https://vega.github.io/vega-datasets/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']
要列出本地数据集(即与包捆绑在一起并且可以在没有Web连接的情况下使用的数据集),请改用local_data
对象:
>>>fromvega_datasetsimportlocal_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"]
我们计划在未来添加更多的本地数据集,以满足大小和许可限制。如果您想帮助解决这个问题,请参阅local datasets issue。
数据集信息
如果需要有关任何数据集的更多信息,可以使用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
文档字符串的一部分。
包中的所有数据集的描述尚未包括在内;我们希望在将来添加有关此的更多信息。