Skip to content

Commit

Permalink
update: 법정동 및 행정동 관련 코드 파일 업데이트
Browse files Browse the repository at this point in the history
최신 데이터 출처
- 행정기관(행정동) 및 관할구역(법정동) 변경내역(2023. 1. 9.시행

코드 데이터 조회 기능 업데이트
- PublicDataReader.code_bdong(): 법정동코드(실제주소)
- PublicDataReader.code_hdong(): 행정기관코드(행정동)
- PublicDataReader.code_hdong_bdong(): 행정기관코드 + 관할 법정동코드
  • Loading branch information
WooilJeong committed Jan 3, 2023
1 parent 5bb29d0 commit bdc02d7
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 40 deletions.
28 changes: 15 additions & 13 deletions PublicDataReader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
from .config.info import __version__, __author__, __contact__, __github__

__all__ = [
"__version__",
"__author__",
"__contact__",
"__version__",
"__author__",
"__contact__",
"__github__",
"Transaction",
"Building",
"StoreInfo",
"Transportation",
"Kosis",
"VworldData",
"Kamco",
"Nts",
"Transaction",
"Building",
"StoreInfo",
"Transportation",
"Kosis",
"VworldData",
"Kamco",
"Nts",
"Kbland",
"code_bdong",
"get_vworld_data_api_info_by_dataframe",
"code_bdong",
"code_hdong",
"code_hdong_bdong",
"get_vworld_data_api_info_by_dataframe",
"get_vworld_data_api_info_by_dict",
]
2 changes: 1 addition & 1 deletion PublicDataReader/config/info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.0.8"
__version__ = "1.0.9"
__author__ = "정우일(Wooil Jeong)"
__contact__ = "[email protected]"
__github__ = "https://github.com/WooilJeong/PublicDataReader"
2 changes: 1 addition & 1 deletion PublicDataReader/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
from PublicDataReader.kbland.kbland import Kbland

# 코드 데이터 조회
from PublicDataReader.utils.code import code_bdong, get_vworld_data_api_info_by_dataframe, get_vworld_data_api_info_by_dict
from PublicDataReader.utils.code import code_bdong, code_hdong, code_hdong_bdong, get_vworld_data_api_info_by_dataframe, get_vworld_data_api_info_by_dict
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion PublicDataReader/raw/code_bdong.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions PublicDataReader/raw/code_hdong.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions PublicDataReader/raw/code_hdong_bdong.json

Large diffs are not rendered by default.

44 changes: 32 additions & 12 deletions PublicDataReader/utils/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,51 @@

_path = os.path.dirname(__file__)
_project_root_path = os.path.dirname(_path)
_json_file_path = f"""{_project_root_path}/raw/code_bdong.json"""
_code_bdong_json_path = f"""{_project_root_path}/raw/code_bdong.json"""
_code_hdong_json_path = f"""{_project_root_path}/raw/code_hdong.json"""
_code_hdong_bdong_json_path = f"""{_project_root_path}/raw/code_hdong_bdong.json"""
_code_vworld_json_path = f"""{_project_root_path}/raw/code_vworld.json"""


def code_bdong():
def read_json_file(file_path):
"""
법정동코드 테이블 반환
json 파일 읽기
"""
with open(f"""{_json_file_path}""", "r") as f:
with open(file_path, "r") as f:
data = f.read()
return pd.DataFrame(json.loads(data))
return json.loads(data)


def code_bdong():
"""
법정동코드(실제주소) 데이터 반환
"""
return pd.DataFrame(read_json_file(_code_bdong_json_path))


def code_hdong():
"""
행정기관코드(행정동) 데이터 반환
"""
return pd.DataFrame(read_json_file(_code_hdong_json_path))


def code_hdong_bdong():
"""
행정기관코드 + 관할 법정동코드 데이터 반환
"""
return pd.DataFrame(read_json_file(_code_hdong_bdong_json_path))


def get_vworld_data_api_info_by_dataframe():
"""
vworld 코드 테이블 반환
vworld 코드 데이터 반환
"""
with open(f"""{_project_root_path}/raw/code_vworld.json""", "r") as f:
data = f.read()
return pd.DataFrame(json.loads(data).items(), columns=["서비스명","서비스ID"])
return pd.DataFrame(read_json_file(_code_vworld_json_path).items(), columns=["서비스명", "서비스ID"])


def get_vworld_data_api_info_by_dict():
"""
vworld 코드 테이블 반환
"""
with open(f"""{_project_root_path}/raw/code_vworld.json""", "r") as f:
data = f.read()
return json.loads(data)
return read_json_file(_code_vworld_json_path)
73 changes: 61 additions & 12 deletions etc/create_code_bdong_file.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,90 @@
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import json\n",
"import glob\n",
"\n",
"# 법정동코드 최신 엑셀 파일 데이터프레임으로 로드\n",
"df = pd.read_excel(\"./PublicDataReader/raw/KIKcd_B.20220701(말소코드포함).xlsx\", dtype=str)\n"
"법정동코드_경로 = glob.glob(\"../PublicDataReader/raw/KIKcd_B*.xlsx\")[0]\n",
"행정동코드_경로 = glob.glob(\"../PublicDataReader/raw/KIKcd_H*.xlsx\")[0]\n",
"혼합코드_경로 = glob.glob(\"../PublicDataReader/raw/KIKmix*.xlsx\")[0]\n",
"\n",
"법정동코드 = pd.read_excel(법정동코드_경로, dtype=str)\n",
"행정동코드 = pd.read_excel(행정동코드_경로, dtype=str)\n",
"혼합코드 = pd.read_excel(혼합코드_경로, dtype=str)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"법정동코드['시도코드'] = 법정동코드['법정동코드'].str[:2]\n",
"법정동코드['시군구코드'] = 법정동코드['법정동코드'].str[:5]\n",
"컬럼목록 = ['시도코드','시도명','시군구코드','시군구명','법정동코드','읍면동명','동리명','생성일자','말소일자']\n",
"법정동코드 = 법정동코드[컬럼목록]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"행정동코드['시도코드'] = 행정동코드['행정동코드'].str[:2]\n",
"행정동코드['시군구코드'] = 행정동코드['행정동코드'].str[:5]\n",
"컬럼목록 = ['시도코드','시도명','시군구코드','시군구명','행정동코드','읍면동명','생성일자','말소일자']\n",
"행정동코드 = 행정동코드[컬럼목록]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df['시도코드'] = df['법정동코드'].str[:2]\n",
"df['시군구코드'] = df['법정동코드'].str[:5]\n",
"df = df[['시도코드','시도명','시군구코드','시군구명','법정동코드','읍면동명','동리명','생성일자','말소일자']]"
"혼합코드['시도코드'] = 혼합코드['행정동코드'].str[:2]\n",
"혼합코드['시군구코드'] = 혼합코드['행정동코드'].str[:5]\n",
"컬럼목록 = ['시도코드','시도명','시군구코드','시군구명','행정동코드','읍면동명','법정동코드','동리명','생성일자','말소일자']\n",
"혼합코드 = 혼합코드[컬럼목록]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 데이터프레임을 딕셔너리로 변환\n",
"df_dict = df.to_dict()\n",
"법정동코드_딕셔너리 = 법정동코드.to_dict()\n",
"행정동코드_딕셔너리 = 행정동코드.to_dict()\n",
"혼합코드_딕셔너리 = 혼합코드.to_dict()\n",
"\n",
"with open(\"../PublicDataReader/raw/code_bdong.json\", \"w\") as f:\n",
" f.write(json.dumps(법정동코드_딕셔너리))\n",
" f.close()\n",
"\n",
"with open(\"../PublicDataReader/raw/code_hdong.json\", \"w\") as f:\n",
" f.write(json.dumps(행정동코드_딕셔너리))\n",
" f.close()\n",
"\n",
"with open(\"./PublicDataReader/raw/code_bdong.json\", \"w\") as f:\n",
" f.write(json.dumps(df_dict))\n",
"with open(\"../PublicDataReader/raw/code_hdong_bdong.json\", \"w\") as f:\n",
" f.write(json.dumps(혼합코드_딕셔너리))\n",
" f.close()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"- 데이터 출처: [행정기관(행정동) 및 관할구역(법정동) 변경내역(2023. 1. 9.시행)](https://www.mois.go.kr/frt/bbs/type001/commonSelectBoardArticle.do;jsessionid=03-7OoZXUAtTvyqlKaaBpHl+.node40?bbsId=BBSMSTR_000000000052&nttId=97730)"
]
}
],
"metadata": {
Expand All @@ -55,7 +104,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.9.12"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
138 changes: 138 additions & 0 deletions test/test_code_json.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"from pathlib import Path\n",
"sys.path.append(str(Path(os.getcwd()).parent))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import PublicDataReader as pdr\n",
"pdr.__version__"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"법정동코드 = pdr.code_bdong()\n",
"행정동코드 = pdr.code_hdong()\n",
"행정동코드_법정동코드 = pdr.code_hdong_bdong()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pdr.get_vworld_data_api_info_by_dict()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pdr.get_vworld_data_api_info_by_dataframe()"
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "venv",
"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.12"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {
"height": "calc(100% - 180px)",
"left": "10px",
"top": "150px",
"width": "234.707px"
},
"toc_section_display": true,
"toc_window_display": true
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"oldHeight": 237.13578,
"position": {
"height": "440.117px",
"left": "491.674px",
"right": "20px",
"top": "85.9445px",
"width": "613.965px"
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"varInspector_section_display": "block",
"window_display": false
},
"vscode": {
"interpreter": {
"hash": "fcea6e6e55b259976681c8a35a3648f8ff7299129df47a05aebb6686c5e7010e"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit bdc02d7

Please sign in to comment.