Skip to content

Commit

Permalink
Update Preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyeongje committed May 11, 2024
1 parent fc6129b commit 18335f3
Show file tree
Hide file tree
Showing 31 changed files with 36,708 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8349c3c3",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import os\n",
"import json\n",
"from time import sleep\n",
"import requests\n",
"import googlemaps"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "dd65a263",
"metadata": {},
"outputs": [],
"source": [
"from urllib.parse import quote\n",
"from urllib.request import Request, urlopen\n",
"import ssl\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c67b8c21",
"metadata": {},
"outputs": [],
"source": [
"API_KEY = \"********\"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "624a943f",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|████████████████████████████████████████████████████████████████████████████████| 149/149 [00:17<00:00, 8.42it/s]\n",
"100%|██████████████████████████████████████████████████████████████████████████████████| 26/26 [00:04<00:00, 6.50it/s]\n",
"100%|██████████████████████████████████████████████████████████████████████████████████| 52/52 [00:08<00:00, 6.18it/s]\n",
"100%|████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:00<00:00, 6.64it/s]\n"
]
}
],
"source": [
"from tqdm import tqdm\n",
"\n",
"maps = googlemaps.Client(key=API_KEY)\n",
"\n",
"lst = ['공동생활가정_경기도', '단기거주시설_경기도', '중증장애인거주시설_경기도', '지체장애인시설_경기도']\n",
"for fname in lst:\n",
" try:\n",
" df = pd.read_csv(f'{fname}.csv')\n",
" except:\n",
" df = pd.read_csv(f'{fname}.csv', encoding='cp949')\n",
" \n",
" lat, lon = [], []\n",
"\n",
" for address in tqdm(df['시설주소']):\n",
" try:\n",
" geo_location = maps.geocode(address)[0].get('geometry')\n",
" lat.append(geo_location['location']['lat'])\n",
" lon.append(geo_location['location']['lng']) \n",
" except:\n",
" lat.append('')\n",
" lon.append('')\n",
" print(f\"{address} 에러\")\n",
"\n",
" df['lat'] = lat\n",
" df['lon'] = lon\n",
"\n",
" df.to_csv(f'{fname}_위경도.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b4c1fdd5",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
118 changes: 118 additions & 0 deletions src/db/proprecessing/disability_facilities/extract_latlon.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8349c3c3",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import os\n",
"import json\n",
"from time import sleep\n",
"import requests\n",
"import googlemaps"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "dd65a263",
"metadata": {},
"outputs": [],
"source": [
"from urllib.parse import quote\n",
"from urllib.request import Request, urlopen\n",
"import ssl\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c67b8c21",
"metadata": {},
"outputs": [],
"source": [
"API_KEY = \"********\"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "624a943f",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|████████████████████████████████████████████████████████████████████████████████| 149/149 [00:17<00:00, 8.42it/s]\n",
"100%|██████████████████████████████████████████████████████████████████████████████████| 26/26 [00:04<00:00, 6.50it/s]\n",
"100%|██████████████████████████████████████████████████████████████████████████████████| 52/52 [00:08<00:00, 6.18it/s]\n",
"100%|████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:00<00:00, 6.64it/s]\n"
]
}
],
"source": [
"from tqdm import tqdm\n",
"\n",
"maps = googlemaps.Client(key=API_KEY)\n",
"\n",
"lst = ['공동생활가정_경기도', '단기거주시설_경기도', '중증장애인거주시설_경기도', '지체장애인시설_경기도']\n",
"for fname in lst:\n",
" try:\n",
" df = pd.read_csv(f'{fname}.csv')\n",
" except:\n",
" df = pd.read_csv(f'{fname}.csv', encoding='cp949')\n",
" \n",
" lat, lon = [], []\n",
"\n",
" for address in tqdm(df['시설주소']):\n",
" try:\n",
" geo_location = maps.geocode(address)[0].get('geometry')\n",
" lat.append(geo_location['location']['lat'])\n",
" lon.append(geo_location['location']['lng']) \n",
" except:\n",
" lat.append('')\n",
" lon.append('')\n",
" print(f\"{address} 에러\")\n",
"\n",
" df['lat'] = lat\n",
" df['lon'] = lon\n",
"\n",
" df.to_csv(f'{fname}_위경도.csv', index=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b4c1fdd5",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 18335f3

Please sign in to comment.