Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Eric Simon
fso_metadata_fork
Commits
50901b87
Commit
50901b87
authored
Dec 08, 2021
by
Eric Simon
Browse files
Auto-saving for eric.simon@bfs.admin.ch on branch master from commit
c89d3247
parent
c89d3247
Pipeline
#290970
passed with stage
in 18 minutes and 41 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
examples.ipynb
View file @
50901b87
%% Cell type:markdown id:fcad4b17 tags:
# Examples notebook
In this notebook, we show one example per possible API call.
%% Cell type:markdown id:42738876-1f79-42a1-90b6-974b12c43ba5 tags:
## Installation
%% Cell type:code id:41518c2a-89fb-42dd-a655-81a2f14f0fa3 tags:
```
python
!
pip
uninstall
fso_metadata
-
y
!
pip
install
fso_metadata
```
%%%% Output: stream
Found existing installation: fso-metadata 0.
6
Uninstalling fso-metadata-0.
6
:
Successfully uninstalled fso-metadata-0.
6
Found existing installation: fso-metadata 0.
8
Uninstalling fso-metadata-0.
8
:
Successfully uninstalled fso-metadata-0.
8
Collecting fso_metadata
Using cached fso_metadata-0.6-py3-none-any.whl
Using cached fso_metadata-0.8-py3-none-any.whl
Requirement already satisfied: openpyxl in /opt/conda/lib/python3.9/site-packages (from fso_metadata) (3.0.9)
Requirement already satisfied: pandasdmx in /opt/conda/lib/python3.9/site-packages (from fso_metadata) (1.6.0)
Requirement already satisfied: pandas in /opt/conda/lib/python3.9/site-packages (from fso_metadata) (1.3.4)
Requirement already satisfied: openpyxl in /opt/conda/lib/python3.9/site-packages (from fso_metadata) (3.0.9)
Requirement already satisfied: et-xmlfile in /opt/conda/lib/python3.9/site-packages (from openpyxl->fso_metadata) (1.1.0)
Requirement already satisfied: pytz>=2017.3 in /opt/conda/lib/python3.9/site-packages (from pandas->fso_metadata) (2021.1)
Requirement already satisfied: numpy>=1.17.3 in /opt/conda/lib/python3.9/site-packages (from pandas->fso_metadata) (1.21.2)
Requirement already satisfied: numpy>=1.17.3 in /opt/conda/lib/python3.9/site-packages (from pandas->fso_metadata) (1.21.4)
Requirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/lib/python3.9/site-packages (from pandas->fso_metadata) (2.8.2)
Requirement already satisfied: pytz>=2017.3 in /opt/conda/lib/python3.9/site-packages (from pandas->fso_metadata) (2021.1)
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)
Requirement already satisfied: pydantic<1.8,>=1.7.1 in /opt/conda/lib/python3.9/site-packages (from pandasdmx->fso_metadata) (1.7.4)
Requirement already satisfied: requests>=2.7 in /opt/conda/lib/python3.9/site-packages (from pandasdmx->fso_metadata) (2.26.0)
Requirement already satisfied: lxml>=3.6 in /opt/conda/lib/python3.9/site-packages (from pandasdmx->fso_metadata) (4.6.3)
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)
Requirement already satisfied: lxml>=3.6 in /opt/conda/lib/python3.9/site-packages (from pandasdmx->fso_metadata) (4.6.4)
Requirement already satisfied: pydantic<1.8,>=1.7.1 in /opt/conda/lib/python3.9/site-packages (from pandasdmx->fso_metadata) (1.7.4)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.9/site-packages (from requests>=2.7->pandasdmx->fso_metadata) (3.1)
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)
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)
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)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.9/site-packages (from requests>=2.7->pandasdmx->fso_metadata) (3.1)
Installing collected packages: fso-metadata
Successfully installed fso-metadata-0.
6
[33mWARNING: You are using pip version 21.2.4; however, version 21.3 is available.
Successfully installed fso-metadata-0.
8
[33mWARNING: You are using pip version 21.2.4; however, version 21.3
.1
is available.
You should consider upgrading via the '/opt/conda/bin/python3 -m pip install --upgrade pip' command.[0m
%% Cell type:markdown id:d307d6fd-bc9e-46d6-960d-567c5ab3d9a4 tags:
# Import functions
%% Cell type:code id:a529fab5-af2f-4439-b98e-13d814b00a94 tags:
```
python
import
fso_metadata
```
%%%% Output: stream
/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
warn(
%% Cell type:code id:486bc684-f4a1-4b26-80ff-c156c51fdb97 tags:
```
python
from
fso_metadata
import
(
get_codelist
,
get_data_structure
,
get_nomenclature_one_level
,
get_nomenclature_multiple_levels
,
)
```
%% Cell type:markdown id:94312182-0616-4938-8d82-d666611bf64d tags:
## Available everywhere with the interoperability plateform (i14y)
%% Cell type:markdown id:bdd766a5-c013-449c-9fd4-7356835396af tags:
[
i14y Swagger UI
](
https://www.i14y.admin.ch/api/index.html
)
%% Cell type:markdown id:446b07a4 tags:
### Code List
%% Cell type:code id:317c3e55 tags:
```
python
# Get a codelist pd.Serie based on an identifier
codelist
=
get_codelist
(
identifier
=
'CL_NOGA_SECTION'
,
export_format
=
"SDMX-ML"
,
version_format
=
2.1
,
annotations
=
True
)
codelist
```
%%%% Output: execute_result
CL_NOGA_SECTION
A AGRICULTURE, FORESTRY AND FISHING
B MINING AND QUARRYING
C MANUFACTURING
D ELECTRICITY, GAS, STEAM AND AIR-CONDITIONING S...
E WATER SUPPLY; SEWERAGE, WASTE MANAGEMENT AND R...
F CONSTRUCTION
G WHOLESALE AND RETAIL TRADE; REPAIR OF MOTOR VE...
H TRANSPORTATION AND STORAGE
I ACCOMMODATION AND FOOD SERVICE ACTIVITIES
J INFORMATION AND COMMUNICATION
K FINANCIAL AND INSURANCE ACTIVITIES
L REAL ESTATE ACTIVITIES
M PROFESSIONAL, SCIENTIFIC AND TECHNICAL ACTIVITIES
N ADMINISTRATIVE AND SUPPORT SERVICE ACTIVITIES
O PUBLIC ADMINISTRATION AND DEFENCE; COMPULSORY ...
P EDUCATION
Q HUMAN HEALTH AND SOCIAL WORK ACTIVITIES
R ARTS, ENTERTAINMENT AND RECREATION
S OTHER SERVICE ACTIVITIES
T ACTIVITIES OF HOUSEHOLDS AS EMPLOYERS; UNDIFFE...
U ACTIVITIES OF EXTRATERRITORIAL ORGANISATIONS A...
Name: NOGA Section, dtype: object
%% Cell type:markdown id:c945eee9-8908-4012-b022-af419d5999b9 tags:
### Data Structures
%% Cell type:code id:56e92700-881f-48af-81d4-1ed622b87400 tags:
```
python
# Get the data structure
data_structure
=
get_data_structure
(
identifier
=
'HCL_CH_ISCO_19_PROF'
,
language
=
'it'
)
data_structure
```
%%%% Output: execute_result
{'type': 'https://httpstatuses.com/404',
'title': 'Not Found',
'status': 404,
'detail': 'DataStructure with type Nomenclature and identifiers
HCL_CH_ISCO_19_PROF/HR_CH_ISCO_19_PROF
is not supported.',
'traceId': '|
6d3c55d1-4ee6924f4e8dca24
.'}
'detail': 'DataStructure with type Nomenclature and
no source
identifiers is not supported.',
'traceId': '|
33497585-4b188072f6327409
.'}
%% Cell type:markdown id:99f3ee98 tags:
### Nomenclature
%% Cell type:code id:dbc2f301 tags:
```
python
# Get one level of a nomenclature in a dataframe
filters
=
{
'code'
:
[
'1'
]}
# TODO: ask what filters are and how they work
single_level
=
get_nomenclature_one_level
(
identifier
=
'HCL_CH_ISCO_19_PROF'
,
filters
=
filters
,
level_number
=
2
,
language
=
'fr'
,
annotations
=
False
)
single_level
.
head
()
```
%%%% Output: execute_result
Code Parent Name_fr
0 01 0 Officiers des forces armées
1 02 0 Sous-officiers des forces armées
2 03 0 Autres membres des forces armées
3 10 1 Directeurs, cadres de direction et gérants, sip
4 11 1 Directeurs généraux, cadres supérieurs et memb...
%% Cell type:code id:94499315 tags:
```
python
# Get multiple levels of a nomenclature in a dataframe
filters
=
{
'code'
:
[
'1'
]}
multiple_levels
=
get_nomenclature_multiple_levels
(
identifier
=
'HCL_CH_ISCO_19_PROF'
,
level_from
=
1
,
level_to
=
4
,
filters
=
filters
,
language
=
'en'
,
annotations
=
True
)
multiple_levels
.
head
(
5
)
```
%%%% Output: execute_result
Major_groups Sub-major_groups Minor_groups Unit_groups Code Name_en
0 0 NaN NaN NaN 0 NaN
1
0
01 NaN NaN 01 NaN
2
0
01
011 NaN 011 NaN
3
0
01
011
0110 0110 NaN
4
0
02
011
0110
02 NaN
1
NaN
01 NaN NaN 01 NaN
2
NaN
NaN
011 NaN 011 NaN
3
NaN
NaN
NaN
0110 0110 NaN
4
NaN
02
NaN
NaN
02 NaN
%% Cell type:code id:377a05a0-a814-401e-b026-aeca2feafbd1 tags:
```
python
```
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment