1

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

  • How are you importing the data? You say, "I am reading it into a collection" -- what does your code to do that look like? – DraftyHat Sep 02 '22 at 19:18
  • So I am using a Jupyter notebook and following the method outlined in this repository https://github.com/virtualarchitectures/CSO_Ireland_JSONStat4Py/blob/master/CSO_Ireland_JSONStat4Py.ipynb Apologies cannot add the individual lines to this comment with proper formatting but there are only a few preceding steps. – David Graham Sep 03 '22 at 10:29

1 Answers1

0

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.

DraftyHat
  • 428
  • 1
  • 2
  • 6