Commit 7b467d3c authored by Pauline Maury Laribière's avatar Pauline Maury Laribière
Browse files

Auto-saving for pauline.maury-laribiere on branch quick_fix from commit bc5c3716

parent 9372d962
%% Cell type:markdown id:fcad4b17 tags:
# Examples notebook
In this notebook, we show one example per possible API call.
%% Cell type:markdown id:d307d6fd-bc9e-46d6-960d-567c5ab3d9a4 tags:
# Import functions
%% Cell type:code id:486bc684-f4a1-4b26-80ff-c156c51fdb97 tags:
``` python
from fso_metadata.api_call import (
get_codelist,
get_data_structure,
get_nomenclature_one_level,
get_nomenclature_multiple_levels,
)
```
%%%% 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: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': '|6d3c8ccb-4ee6924f4e8dca24.'}
%% 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 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
```
%% 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.7
Uninstalling fso-metadata-0.7:
Successfully uninstalled fso-metadata-0.7
Collecting fso_metadata
Using cached fso_metadata-0.6-py3-none-any.whl
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)
Downloading fso_metadata-0.8.tar.gz (6.3 kB)
Requirement already satisfied: openpyxl in /opt/conda/lib/python3.9/site-packages (from fso_metadata) (3.0.9)
Requirement already satisfied: pandas in /opt/conda/lib/python3.9/site-packages (from fso_metadata) (1.3.4)
Requirement already satisfied: pandasdmx in /opt/conda/lib/python3.9/site-packages (from fso_metadata) (1.6.0)
Requirement already satisfied: et-xmlfile in /opt/conda/lib/python3.9/site-packages (from openpyxl->fso_metadata) (1.1.0)
Requirement already satisfied: numpy>=1.17.3 in /opt/conda/lib/python3.9/site-packages (from pandas->fso_metadata) (1.21.3)
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: python-dateutil>=2.7.3 in /opt/conda/lib/python3.9/site-packages (from pandas->fso_metadata) (2.8.2)
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: requests>=2.7 in /opt/conda/lib/python3.9/site-packages (from pandasdmx->fso_metadata) (2.26.0)
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: 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: 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: 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: 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)
Building wheels for collected packages: fso-metadata
Building wheel for fso-metadata (setup.py) ... [?25ldone
[?25h Created wheel for fso-metadata: filename=fso_metadata-0.8-py3-none-any.whl size=7532 sha256=f9698cf8c11edb3036ccf3abd1a273997931597c986ff76126fe51d72cbb0467
Stored in directory: /home/jovyan/.cache/pip/wheels/a0/18/ba/1a794412ee86616cb0bfd5ce387bf42c3a35685e8535941882
Successfully built fso-metadata
Installing collected packages: fso-metadata
Successfully installed fso-metadata-0.6
WARNING: You are using pip version 21.2.4; however, version 21.3 is available.
Successfully installed fso-metadata-0.8
WARNING: 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.
%% 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.'}
'traceId': '|6d3c8cd9-4ee6924f4e8dca24.'}
%% 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
```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment