Newer
Older
{
"cells": [
{
"cell_type": "markdown",
"id": "fcad4b17",
"metadata": {},
"source": [
"\n",
"In this notebook, we show one example per possible API call."
]
},
"cell_type": "markdown",
"id": "42738876-1f79-42a1-90b6-974b12c43ba5",
"output_type": "stream",
"text": [
"Found existing installation: fso-metadata 0.6\n",
"Uninstalling fso-metadata-0.6:\n",
" Successfully uninstalled fso-metadata-0.6\n",
"Collecting fso_metadata\n",
" Using cached fso_metadata-0.6-py3-none-any.whl\n",
"Requirement already satisfied: pandasdmx in /opt/conda/lib/python3.9/site-packages (from fso_metadata) (1.6.0)\n",
"Requirement already satisfied: pandas in /opt/conda/lib/python3.9/site-packages (from fso_metadata) (1.3.4)\n",
"Requirement already satisfied: openpyxl in /opt/conda/lib/python3.9/site-packages (from fso_metadata) (3.0.9)\n",
"Requirement already satisfied: et-xmlfile in /opt/conda/lib/python3.9/site-packages (from openpyxl->fso_metadata) (1.1.0)\n",
"Requirement already satisfied: pytz>=2017.3 in /opt/conda/lib/python3.9/site-packages (from pandas->fso_metadata) (2021.1)\n",
"Requirement already satisfied: numpy>=1.17.3 in /opt/conda/lib/python3.9/site-packages (from pandas->fso_metadata) (1.21.2)\n",
"Requirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/lib/python3.9/site-packages (from pandas->fso_metadata) (2.8.2)\n",
"Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.9/site-packages (from python-dateutil>=2.7.3->pandas->fso_metadata) (1.16.0)\n",
"Requirement already satisfied: pydantic<1.8,>=1.7.1 in /opt/conda/lib/python3.9/site-packages (from pandasdmx->fso_metadata) (1.7.4)\n",
"Requirement already satisfied: requests>=2.7 in /opt/conda/lib/python3.9/site-packages (from pandasdmx->fso_metadata) (2.26.0)\n",
"Requirement already satisfied: lxml>=3.6 in /opt/conda/lib/python3.9/site-packages (from pandasdmx->fso_metadata) (4.6.3)\n",
"Requirement already satisfied: charset-normalizer~=2.0.0 in /opt/conda/lib/python3.9/site-packages (from requests>=2.7->pandasdmx->fso_metadata) (2.0.0)\n",
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.9/site-packages (from requests>=2.7->pandasdmx->fso_metadata) (1.26.6)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.9/site-packages (from requests>=2.7->pandasdmx->fso_metadata) (2021.5.30)\n",
"Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.9/site-packages (from requests>=2.7->pandasdmx->fso_metadata) (3.1)\n",
"Installing collected packages: fso-metadata\n",
"Successfully installed fso-metadata-0.6\n",
"\u001b[33mWARNING: You are using pip version 21.2.4; however, version 21.3 is available.\n",
"You should consider upgrading via the '/opt/conda/bin/python3 -m pip install --upgrade pip' command.\u001b[0m\n"
"!pip install fso_metadata"
]
},
{
"cell_type": "markdown",
"id": "d307d6fd-bc9e-46d6-960d-567c5ab3d9a4",
"metadata": {},
"source": [
"# Import functions"
]
},
{
"cell_type": "code",
"id": "a529fab5-af2f-4439-b98e-13d814b00a94",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/conda/lib/python3.9/site-packages/pandasdmx/remote.py:11: RuntimeWarning: optional dependency requests_cache is not installed; cache options to Session() have no effect\n",
" warn(\n"
]
}
],
"source": [
"import fso_metadata"
]
},
{
"cell_type": "code",
"id": "486bc684-f4a1-4b26-80ff-c156c51fdb97",
"metadata": {},
"outputs": [],
"source": [
"from fso_metadata import (\n",
" get_nomenclature_one_level,\n",
" get_nomenclature_multiple_levels,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "94312182-0616-4938-8d82-d666611bf64d",
"metadata": {},
"source": [
"## Available everywhere with the interoperability plateform (i14y)"
]
},
{
"cell_type": "markdown",
"id": "bdd766a5-c013-449c-9fd4-7356835396af",
"metadata": {},
"source": [
"[i14y Swagger UI](https://www.i14y.admin.ch/api/index.html)"
]
},
{
"cell_type": "markdown",
"id": "446b07a4",
"metadata": {},
"source": [
"### Code List"
]
},
{
"cell_type": "code",
"id": "317c3e55",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CL_NOGA_SECTION\n",
"A AGRICULTURE, FORESTRY AND FISHING\n",
"B MINING AND QUARRYING\n",
"C MANUFACTURING\n",
"D ELECTRICITY, GAS, STEAM AND AIR-CONDITIONING S...\n",
"E WATER SUPPLY; SEWERAGE, WASTE MANAGEMENT AND R...\n",
"F CONSTRUCTION\n",
"G WHOLESALE AND RETAIL TRADE; REPAIR OF MOTOR VE...\n",
"H TRANSPORTATION AND STORAGE\n",
"I ACCOMMODATION AND FOOD SERVICE ACTIVITIES\n",
"J INFORMATION AND COMMUNICATION\n",
"K FINANCIAL AND INSURANCE ACTIVITIES\n",
"L REAL ESTATE ACTIVITIES\n",
"M PROFESSIONAL, SCIENTIFIC AND TECHNICAL ACTIVITIES\n",
"N ADMINISTRATIVE AND SUPPORT SERVICE ACTIVITIES\n",
"O PUBLIC ADMINISTRATION AND DEFENCE; COMPULSORY ...\n",
"P EDUCATION\n",
"Q HUMAN HEALTH AND SOCIAL WORK ACTIVITIES\n",
"R ARTS, ENTERTAINMENT AND RECREATION\n",
"S OTHER SERVICE ACTIVITIES\n",
"T ACTIVITIES OF HOUSEHOLDS AS EMPLOYERS; UNDIFFE...\n",
"U ACTIVITIES OF EXTRATERRITORIAL ORGANISATIONS A...\n",
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get a codelist pd.Serie based on an identifier\n",
"codelist = get_codelist(identifier='CL_NOGA_SECTION', export_format=\"SDMX-ML\", version_format=2.1, annotations=True)\n",
{
"cell_type": "markdown",
"id": "c945eee9-8908-4012-b022-af419d5999b9",
"metadata": {},
"source": [
"### Data Structures"
]
},
{
"cell_type": "code",
"id": "56e92700-881f-48af-81d4-1ed622b87400",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'type': 'https://httpstatuses.com/404',\n",
" 'title': 'Not Found',\n",
" 'status': 404,\n",
" 'detail': 'DataStructure with type Nomenclature and identifiers HCL_CH_ISCO_19_PROF/HR_CH_ISCO_19_PROF is not supported.',\n",
" 'traceId': '|6d3c55d1-4ee6924f4e8dca24.'}"
"metadata": {},
"output_type": "execute_result"
}
],
"# Get the data structure\n",
"data_structure = get_data_structure(identifier='HCL_CH_ISCO_19_PROF', language='it')\n",
"data_structure"
]
},
{
"cell_type": "markdown",
"id": "99f3ee98",
"metadata": {},
"source": [
"### Nomenclature"
]
},
{
"cell_type": "code",
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
"id": "dbc2f301",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Code</th>\n",
" <th>Parent</th>\n",
" <th>Name_fr</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>01</td>\n",
" <td>0</td>\n",
" <td>Officiers des forces armées</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>02</td>\n",
" <td>0</td>\n",
" <td>Sous-officiers des forces armées</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>03</td>\n",
" <td>0</td>\n",
" <td>Autres membres des forces armées</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>10</td>\n",
" <td>1</td>\n",
" <td>Directeurs, cadres de direction et gérants, sip</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>11</td>\n",
" <td>1</td>\n",
" <td>Directeurs généraux, cadres supérieurs et memb...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Code Parent Name_fr\n",
"0 01 0 Officiers des forces armées\n",
"1 02 0 Sous-officiers des forces armées\n",
"2 03 0 Autres membres des forces armées\n",
"3 10 1 Directeurs, cadres de direction et gérants, sip\n",
"4 11 1 Directeurs généraux, cadres supérieurs et memb..."
]
},
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get one level of a nomenclature in a dataframe\n",
"filters = {'code': ['1']} # TODO: ask what filters are and how they work\n",
"single_level = get_nomenclature_one_level(identifier='HCL_CH_ISCO_19_PROF', filters=filters, level_number=2, language='fr', annotations=False)\n",
"single_level.head()"
]
},
{
"cell_type": "code",
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
"id": "94499315",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Major_groups</th>\n",
" <th>Sub-major_groups</th>\n",
" <th>Minor_groups</th>\n",
" <th>Unit_groups</th>\n",
" <th>Code</th>\n",
" <th>Name_en</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0</td>\n",
" <td>01</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>01</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0</td>\n",
" <td>01</td>\n",
" <td>011</td>\n",
" <td>NaN</td>\n",
" <td>011</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0</td>\n",
" <td>01</td>\n",
" <td>011</td>\n",
" <td>0110</td>\n",
" <td>0110</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0</td>\n",
" <td>02</td>\n",
" <td>011</td>\n",
" <td>0110</td>\n",
" <td>02</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Major_groups Sub-major_groups Minor_groups Unit_groups Code Name_en\n",
"0 0 NaN NaN NaN 0 NaN\n",
"1 0 01 NaN NaN 01 NaN\n",
"2 0 01 011 NaN 011 NaN\n",
"3 0 01 011 0110 0110 NaN\n",
"4 0 02 011 0110 02 NaN"
]
},
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get multiple levels of a nomenclature in a dataframe\n",
"filters = {'code': ['1']}\n",
"multiple_levels = get_nomenclature_multiple_levels(identifier='HCL_CH_ISCO_19_PROF', level_from=1, level_to=4, filters=filters, language='en', annotations=True)\n",
"multiple_levels.head(5)"
]
},
{
"cell_type": "code",
"id": "377a05a0-a814-401e-b026-aeca2feafbd1",
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}