Jsonstatdataset rename

Question:

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 e.g.

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

Thanks

Asked By: David Graham

||

Answers:

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"). The data is from https://www.cso.ie/en/index.html , search for "Residential Property Price Index" and download the .json file.

Answered By: DraftyHat