简体   繁体   English

Jsonstat 数据集重命名

[英]Jsonstatdataset rename

I am trying to read a table from the Central Statistics Office for Ireland.我正在尝试阅读爱尔兰中央统计局的表格。 I am reading it into a collection and successfully displaying the first dataset我正在将它读入一个集合并成功显示第一个数据集

dataset = collection.dataset(0)
print(dataset)

which returns:返回:

name:   'dataset'
label:  'Residential Property Price Index'
source: 'Residential Property Price Index'
size: 16800
+-----+--------------+--------------+------+--------+
| pos | id           | label        | size | role   |
+-----+--------------+--------------+------+--------+
| 0   | STATISTIC    | STATISTIC    | 4    | metric |
| 1   | TLIST(M1)    | TLIST(M1)    | 210  | time   |
| 2   | C02803V03373 | C02803V03373 | 20   |        |
+-----+--------------+--------------+------+--------+ 

I can print out each of the dimensions eg我可以打印出每个尺寸,例如

print(dataset.dimension('STATISTIC'))
print(dataset.dimension('TLIST(M1)'))
print(dataset.dimension('C02803V03373'))

The first dimension is the statistic type, the second is the quarter year and the last is the region of the country.第一个维度是统计类型,第二个维度是季度年,最后一个维度是国家/地区。 My difficulty though is, when I try to retreive a particular statistic for a particular quarter for a particular region I get an error:不过,我的困难是,当我尝试检索特定地区特定季度的特定统计数据时,会出现错误:

dataset.data(STATISTIC='HPM09C04', TLIST(M1)='2022M06'  ,C02803V03373='05')
dataset.data(STATISTIC='HPM09C04', TLIST(M1)='2022M06'  ,C02803V03373='05')
                                       ^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

When "TLIST(M1)" used to be called "QUARTER" this worked fine but clearly the name containing parenthesis is causing an issue.当“TLIST(M1)”曾经被称为“QUARTER”时,这工作得很好,但显然包含括号的名称会导致问题。 If I do not specify a particular quarter, I get the first quarter.如果我没有指定特定季度,我会得到第一季度。

So my question is, is there a way to reference a particular quarter while keeping the name as 'TLIST(M1)' or failing that a way to rename it?所以我的问题是,有没有办法在将名称保持为“TLIST(M1)”的同时引用特定季度,或者没有办法重命名它?

Thanks谢谢

I managed it this way:我是这样管理的:

import jsonstat
dataset = jsonstat.from_file('HPM06.20220902T150925.json')
args={'STATISTIC':'HPM09C04', 'TLIST(M1)':'2022M06'  ,'C02803V03373':'05'}          
answer = dataset.data(**args)
print(answer)
# prints  JsonStatValue(idx=16783, value=11.8, status=None)

I used jsonstat, installed via pip install jsonstat.py (yes, including the ".py").我使用了 jsonstat,通过pip install jsonstat.py (是的,包括“.py”)。 The data is from https://www.cso.ie/en/index.html , search for "Residential Property Price Index" and download the.json file.数据来自https://www.cso.ie/en/index.html ,搜索“住宅物业价格指数”下载.json文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM