用于读取json stat格式数据的库。
jsonstat.p的Python项目详细描述
jsonstat.py是用于读取JSON-stat数据格式的库 由Xavier Badosa维护和提升。 json stat格式是用于发布数据集的json格式。 json stat被一些机构用来发布统计数据。 不完整的列表是:
- Eurostat提供有关欧盟(eu)的统计信息
- Italian National Institute of Statistics Istat
- Central Statistics Office of Ireland
- United Nations Economic Commission for Europe (UNECE) 统计数据是here
- Statistics Norway
- UK Office for national statistics 见their blog post
- 其他…
jsonstat.py库在python中尽量模仿 这是json-stat Javascript Toolkit。 图书馆的目标之一是帮助探索数据集 使用jupyter(ipython)笔记本。
要快速了解此功能,可以从本示例笔记本开始 oecd-canada-jsonstat_v1.html 您还可以从 example directory on github 或者从documentation
作为奖励,jsonstat.py包含一个有用的类来探索数据集 由Istat出版。
您可以找到另一个有用的python库 pyjstat Miguel Expósito Martin关于JSON统计格式。
此库处于测试状态。 我正在积极努力,希望能改进这个项目。 如有任何意见,请随时与我联系gf@26fe.com
你可以在github找到来源, 如果你愿意,你可以打开一个ticket。
您可以在readthedocs找到生成的文档。
安装
pip将安装所有必需的依赖项。用于安装:
pip install jsonstat.py
用法
简单用法
有一个简单的命令行界面,因此您可以尝试在不编写代码的情况下解析jsonstat文件:
# parsing collection $ jsonstat info --cache_dir /tmp http://json-stat.org/samples/oecd-canada.json downloaded file(s) are stored into '/tmp' download 'http://json-stat.org/samples/oecd-canada.json' Jsonsta tCollection contains the following JsonStatDataSet: +-----+----------+ | pos | dataset | +-----+----------+ | 0 | 'oecd' | | 1 | 'canada' | +-----+----------+ # parsing dataset $ jsonstat info --cache_dir /tmp "http://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/en/tesem120?sex=T&precision=1&age=TOTAL&s_adj=NSA" downloaded file(s) are stored into '/tmp' download 'http://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/en/tesem120?sex=T&precision=1&age=TOTAL&s_adj=NSA' name: 'Unemployment rate' label: 'Unemployment rate' size: 467 +-----+-------+-------+------+------+ | pos | id | label | size | role | +-----+-------+-------+------+------+ | 0 | s_adj | s_adj | 1 | | | 1 | age | age | 1 | | | 2 | sex | sex | 1 | | | 3 | geo | geo | 39 | | | 4 | time | time | 12 | | +-----+-------+-------+------+------+
代码示例:
url = 'http://json-stat.org/samples/oecd-canada.json' collection = jsonstat.from_url(url) # print list of dataset contained into the collection print(collection) # select the first dataset of the collection and print a short description oecd = collection.dataset(0) print(oecd) # print description about each dimension of the dataset for d in oecd.dimensions(): print(d) # print a datapoint contained into the dataset print(oecd.value(area='IT', year='2012')) # convert a dataset in pandas dataframe df = oecd.to_data_frame('year')
有关更多python脚本示例,请参见 examples directory。
关于jupyter(ipython)笔记本,请参见 examples-notebooks directory。
支架
这是一个开源项目,在我的业余时间维护。 可能缺少您希望的特定功能或函数。 但事情不必这样:你可以自己为项目开发做出贡献。 或者通知我并要求实施。
应提交错误报告和功能请求 使用github issue tracker。 请提供您看到的任何错误的完整回溯,如果可能,请提供一个示例文件。 如果您无法公开文件,请通过gf@26fe.com与我联系。
您也可以在google group上找到支持。
如何贡献代码
如有任何帮助,请按照以下步骤操作:
- 用叉子叉。为每个独立功能启动一个新的fork,不要试图同时解决所有问题, 对于那些将审阅和合并您的更改的人来说,这更容易。
- 创建功能分支(git checkout -bmy-new-feature)
- 写下你的代码。为您的更改添加单元测试! 如果你增加了一个全新的功能,或者只是改进了一些东西,你可以为此感到骄傲, 因此,将您自己添加到AUTHORS文件:-) 更新文档!
- 提交更改(git commit -am 'Added some feature')
- 推到分支(git push origin my-new-feature)
- 创建新的请求。单击存储库上的大“请求”按钮。 等待您的代码被审查,如果您遵循了所有这些步骤,则合并到主存储库中。
许可证
jsonstat.py是在lgpl许可证下提供的。 请参阅许可证文件。