Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add NAF code sections #15

Merged
merged 2 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions labels/sections_codes_naf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"01":"A","02":"A","03":"A","05":"B","06":"B","07":"B","08":"B","09":"B","10":"C","11":"C","12":"C","13":"C","14":"C","15":"C","16":"C","17":"C","18":"C","19":"C","20":"C","21":"C","22":"C","23":"C","24":"C","25":"C","26":"C","27":"C","28":"C","29":"C","30":"C","31":"C","32":"C","33":"C","35":"D","36":"E","37":"E","38":"E","39":"E","41":"F","42":"F","43":"F","45":"G","46":"G","47":"G","49":"H","50":"H","51":"H","52":"H","53":"H","55":"I","56":"I","58":"J","59":"J","60":"J","61":"J","62":"J","63":"J","64":"K","65":"K","66":"K","68":"L","69":"M","70":"M","71":"M","72":"M","73":"M","74":"M","75":"M","77":"N","78":"N","79":"N","80":"N","81":"N","82":"N","84":"O","85":"P","86":"Q","87":"Q","88":"Q","90":"R","91":"R","92":"R","93":"R","94":"S","95":"S","96":"S","97":"T","98":"T","99":"U"}
65 changes: 64 additions & 1 deletion process-data-before-indexation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"import os, shutil\n",
"import numpy as np\n",
"import swifter\n",
"import math"
"import math\n",
"import json"
]
},
{
Expand Down Expand Up @@ -61,6 +62,18 @@
"os.makedirs(os.path.dirname(OUTPUT_DATA_FOLDER), exist_ok=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if \"LABELS_FOLDER\" not in locals():\n",
" LABELS_FOLDER = \"./labels/\"\n",
"else:\n",
" print(LABELS_FOLDER)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -512,6 +525,47 @@
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Sections Codes NAF"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def load_file(file_name: str):\n",
" with open(file_name) as json_file:\n",
" file_decoded = json.load(json_file)\n",
" return file_decoded\n",
"# sections_NAF = load_file(f\"{LABELS_FOLDER}sections_codes_naf.json\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"sections_NAF = {\n",
"\"01\":\"A\",\"02\":\"A\",\"03\":\"A\",\"05\":\"B\",\"06\":\"B\",\"07\":\"B\",\"08\":\"B\",\"09\":\"B\",\"10\":\"C\",\"11\":\"C\",\"12\":\"C\",\"13\":\"C\",\"14\":\"C\",\n",
" \"15\":\"C\",\"16\":\"C\",\"17\":\"C\",\"18\":\"C\",\"19\":\"C\",\"20\":\"C\",\"21\":\"C\",\"22\":\"C\",\"23\":\"C\",\"24\":\"C\",\"25\":\"C\",\"26\":\"C\",\"27\":\"C\",\n",
" \"28\":\"C\",\"29\":\"C\",\"30\":\"C\",\"31\":\"C\",\"32\":\"C\",\"33\":\"C\",\"35\":\"D\",\"36\":\"E\",\"37\":\"E\",\"38\":\"E\",\"39\":\"E\",\"41\":\"F\",\"42\":\"F\",\n",
" \"43\":\"F\",\"45\":\"G\",\"46\":\"G\",\"47\":\"G\",\"49\":\"H\",\"50\":\"H\",\"51\":\"H\",\"52\":\"H\",\"53\":\"H\",\"55\":\"I\",\"56\":\"I\",\"58\":\"J\",\"59\":\"J\",\n",
" \"60\":\"J\",\"61\":\"J\",\"62\":\"J\",\"63\":\"J\",\"64\":\"K\",\"65\":\"K\",\"66\":\"K\",\"68\":\"L\",\"69\":\"M\",\"70\":\"M\",\"71\":\"M\",\"72\":\"M\",\"73\":\"M\",\n",
" \"74\":\"M\",\"75\":\"M\",\"77\":\"N\",\"78\":\"N\",\"79\":\"N\",\"80\":\"N\",\"81\":\"N\",\"82\":\"N\",\"84\":\"O\",\"85\":\"P\",\"86\":\"Q\",\"87\":\"Q\",\"88\":\"Q\",\n",
" \"90\":\"R\",\"91\":\"R\",\"92\":\"R\",\"93\":\"R\",\"94\":\"S\",\"95\":\"S\",\"96\":\"S\",\"97\":\"T\",\"98\":\"T\",\"99\":\"U\"\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"# Nombre établissements"
]
Expand Down Expand Up @@ -543,6 +597,15 @@
"df_unite_legale = pd.merge(df_unite_legale, df_out2, on=\"siren\", how=\"left\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_unite_legale[\"section_activite_principale\"] = df_unite_legale['activite_principale_unite_legale'].str[:2].map(sections_NAF)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
1 change: 1 addition & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def format_sirene_notebook(**kwargs):
"msgs": "Ran from Airflow " + ENV + " !",
"DATA_DIR": TMP_FOLDER + DAG_FOLDER + DAG_NAME + "/data/",
"OUTPUT_DATA_FOLDER": TMP_FOLDER + DAG_FOLDER + DAG_NAME + "/output/",
"LABELS_FOLDER": TMP_FOLDER + DAG_FOLDER + DAG_NAME + "/labels/",
"ELASTIC_INDEX": elastic_index,
},
)
Expand Down