728x90
๋ฐ์ํ
This guide explains how to fetch data from KOICA OpenAPI and convert it into Excel files using Python code. It includes the process of saving data to files and provides concrete code examples
Guide: Python Code for Converting KOICA OpenAPI Data to Files | Excels
KOICA ์คํAPI๋ฐ์ดํฐ๋ฅผ ํ์ผ๋ฐ์ดํฐ๋ก ๋ณํํ๋ ํ์ด์ฌ ์ฝ๋ ๊ฐ์ด๋
2. Name of data used: KOICA Local Safety Information
(ํ๊ตญ๊ตญ์ ํ๋ ฅ๋จ_ํ์ง ์์ ์ ๋ณด)
Google Colab: https://colab.research.google.com/drive/10BISX58wfqgf2dZSR-izYJjzB1XIpEyU?usp=sharing

1. API ํธ์ถ URL ์ฃผ์ ํ์ธ
- ์์ฒญ์ฃผ์ http://apis.data.go.kr/B260003/LocalSafetyInformationService/getLocalSafetyInformationList
2. ์ผ๋ฐ ์ธ์ฆํค(Decoding) ํ์ธ
3. ํ์ผ๋ฐ์ดํฐ๋ก ๋ณํ
* ํญ๋ชฉ๋ช (๊ตญ๋ฌธ)์ด ์ถ๋ ฅ๋๋๋ก ์ฝ๋ ์ถ๊ฐํจ

์ ์ฒด ์ฝ๋
# 2. ํ๊ตญ๊ตญ์ ํ๋ ฅ๋จ_ํ์ง ์์ ์ ๋ณด
import requests
import pandas as pd
from google.colab import files
# API ์์ฒญ URL ๋ฐ ๊ธฐ๋ณธ ํ๋ผ๋ฏธํฐ ์ค์
# ์๋ serviceKey์๋ ์์ฒญํด์ ๋ถ์ฌ ๋ฐ์ "์ผ๋ฐ ์ธ์ฆํค(Decoding)"๋ก ๋์ฒดํ์ฌ ๊ธฐ์
ํ์
์ผ ํฉ๋๋ค!
service_key = '์ผ๋ฐ ์ธ์ฆํค(Decoding)'
# ๋ฐ์ดํฐ ์์ง ํจ์
def fetch_all_data(url, service_key):
all_data = []
page_no = 1
while True:
params = {
'serviceKey': service_key,
'numOfRows': '1000',
'pageNo': page_no
}
response = requests.get(url, params=params)
if response.status_code == 200:
items = response.json().get('data', [])
if not items:
break
all_data.extend(items)
page_no += 1
else:
print(f"API ์์ฒญ ์คํจ: {response.status_code}")
break
return all_data
# ์ ์ฒด ๋ฐ์ดํฐ ํธ์ถ
all_items = fetch_all_data(url, service_key)
# ํญ๋ชฉ๋ช
(์๋ฌธ)๊ณผ ํญ๋ชฉ๋ช
(๊ตญ๋ฌธ)์ ๋งคํ
column_mapping = {
"country_nm": "ํ๊ธ ๊ตญ๊ฐ๋ช
",
"country_eng_nm": "์๋ฌธ ๊ตญ๊ฐ๋ช
",
"country_iso_alp2": "ISO 2์๋ฆฌ์ฝ๋",
"continent_nm": "๋๋ฅ๋ช
",
"business_type_cd": "์ฌ์
์ ํ์ฝ๋",
"business_type_cd_nm": "์ฌ์
์ ํ๋ช
",
"kor_business_nm": "์ฌ์
๋ช
(๊ตญ๋ฌธ)",
"eng_business_nm": "์ฌ์
๋ช
(์๋ฌธ)",
"business_start_dt": "์ฌ์
์์์ผ",
"business_end_dt": "์ฌ์
์ข
๋ฃ์ผ",
"multi_year_type_cd": "๋ค๋
๊ตฌ๋ถ์ฝ๋",
"multi_year_type_cd_nm": "๋ค๋
๊ตฌ๋ถ์ฝ๋๋ช
",
"bnft_org_nm": "์ํ๊ธฐ๊ด๋ช
",
"business_year": "์ฌ์
๋
๋"
}
# ๋ฐ์ดํฐํ๋ ์ ๋ณํ ๋ฐ ์์
ํ์ผ ์ ์ฅ
if all_items:
df = pd.DataFrame(all_items)
df.rename(columns=column_mapping, inplace=True)
file_path = 'LocalSafetyInformation_All_Kor.xlsx'
df.to_excel(file_path, index=False)
print(f"์ ์ฒด ๋ฐ์ดํฐ๊ฐ '{file_path}' ํ์ผ๋ก ์ ์ฅ๋์์ต๋๋ค.")
files.download(file_path)
else:
print("์๋ต ๋ฐ์ดํฐ์ ํญ๋ชฉ์ด ์์ต๋๋ค.")
Guide: Python Code for Converting KOICA OpenAPI Data to Files | Excels
KOICA ์คํAPI๋ฐ์ดํฐ๋ฅผ ํ์ผ๋ฐ์ดํฐ๋ก ๋ณํํ๋ ํ์ด์ฌ ์ฝ๋ ๊ฐ์ด๋
3. Name of data used: KOICA Local Activity Information
(ํ๊ตญ๊ตญ์ ํ๋ ฅ๋จ_ํ์ง ํ๋์ ๋ณด)
Google Colab: https://colab.research.google.com/drive/10BISX58wfqgf2dZSR-izYJjzB1XIpEyU?usp=sharing

1. API ํธ์ถ URL ์ฃผ์ ํ์ธ
- ์์ฒญ์ฃผ์ http://apis.data.go.kr/B260003/LocalActivityInformationService/getLocalActivityInformationList
2. ์ผ๋ฐ ์ธ์ฆํค(Decoding) ํ์ธ
3. ํ์ผ๋ฐ์ดํฐ๋ก ๋ณํ
* ํญ๋ชฉ๋ช (๊ตญ๋ฌธ)์ด ์ถ๋ ฅ๋๋๋ก ์ฝ๋ ์ถ๊ฐํจ

์ ์ฒด ์ฝ๋
# 3. ํ๊ตญ๊ตญ์ ํ๋ ฅ๋จ_ํ์ง ํ๋์ ๋ณด
import requests
import pandas as pd
from google.colab import files
# API ์์ฒญ URL ๋ฐ ๊ธฐ๋ณธ ํ๋ผ๋ฏธํฐ ์ค์
url = 'http://apis.data.go.kr/B260003/LocalActivityInformationService/getLocalActivityInformationList'
# ์๋ serviceKey์๋ ์์ฒญํด์ ๋ถ์ฌ ๋ฐ์ "์ผ๋ฐ ์ธ์ฆํค(Decoding)"๋ก ๋์ฒดํ์ฌ ๊ธฐ์
ํ์
์ผ ํฉ๋๋ค!
service_key = '์ผ๋ฐ ์ธ์ฆํค(Decoding)'
# ๋ฐ์ดํฐ ์์ง ํจ์
def fetch_all_data(url, service_key):
all_data = []
page_no = 1
while True:
params = {
'serviceKey': service_key,
'numOfRows': '1000',
'pageNo': page_no
}
response = requests.get(url, params=params)
if response.status_code == 200:
items = response.json().get('data', [])
if not items:
break
all_data.extend(items)
page_no += 1
else:
print(f"API ์์ฒญ ์คํจ: {response.status_code}")
break
return all_data
# ์ ์ฒด ๋ฐ์ดํฐ ํธ์ถ
all_items = fetch_all_data(url, service_key)
# ํญ๋ชฉ๋ช
(์๋ฌธ)๊ณผ ํญ๋ชฉ๋ช
(๊ตญ๋ฌธ)์ ๋งคํ
column_mapping = {
"country_nm": "ํ๊ธ ๊ตญ๊ฐ๋ช
",
"country_eng_nm": "์๋ฌธ ๊ตญ๊ฐ๋ช
",
"country_iso_alp2": "ISO 2์๋ฆฌ์ฝ๋",
"continent_nm": "๋๋ฅ๋ช
",
"business_type_cd": "์ฌ์
์ ํ์ฝ๋",
"business_type_cd_nm": "์ฌ์
์ ํ๋ช
",
"kor_business_nm": "์ฌ์
๋ช
(๊ตญ๋ฌธ)",
"eng_business_nm": "์ฌ์
๋ช
(์๋ฌธ)",
"business_start_dt": "์ฌ์
์์์ผ",
"business_end_dt": "์ฌ์
์ข
๋ฃ์ผ",
"multi_year_type_cd": "๋ค๋
๊ตฌ๋ถ์ฝ๋",
"multi_year_type_cd_nm": "๋ค๋
๊ตฌ๋ถ์ฝ๋๋ช
",
"bnft_org_nm": "์ํ๊ธฐ๊ด๋ช
",
"business_year": "์ฌ์
๋
๋"
}
# ๋ฐ์ดํฐํ๋ ์ ๋ณํ ๋ฐ ์์
ํ์ผ ์ ์ฅ
if all_items:
df = pd.DataFrame(all_items)
df.rename(columns=column_mapping, inplace=True)
file_path = 'KOICA_localactivity_kor.xlsx'
df.to_excel(file_path, index=False)
print(f"์ ์ฒด ๋ฐ์ดํฐ๊ฐ '{file_path}' ํ์ผ๋ก ์ ์ฅ๋์์ต๋๋ค.")
files.download(file_path)
else:
print("์๋ต ๋ฐ์ดํฐ์ ํญ๋ชฉ์ด ์์ต๋๋ค.")
728x90
๋ฐ์ํ