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

[DE한경훈] Feat: 한경훈 W4M2 (docker-compose.yml, ananlysis.ipynb, Download_parquet.py, README.md) files submit #259

Open
wants to merge 15 commits into
base: DE한경훈_W4
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions missions/W1/Update_country_region.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pandas as pd
import json
import requests
from io import StringIO
import yaml

# yaml Data config로 가져오기
with open('path_url_settings.yaml', 'r') as file:
config = yaml.safe_load(file)

# 저장하고 다음부터 load할 Region별 국가 Data JSON file
json_path = config['file_name']['region_data_json_file']
# Region을 Update할 URL
csv_url = config['URL']['REGION_UPDATE_URL']

# DataFrame 생성
response = requests.get(csv_url)
if response.status_code == 200:
csv_data = response.content.decode('utf-8')
df = pd.read_csv(StringIO(csv_data))
else:
raise Exception(f"Failed to fetch CSV data: {response.status_code}")

# Region별 Country로 변환
Region_dict = df.groupby('Continent')['Country'].apply(list).to_dict()

# JSON file load
try:
with open(json_path, 'r') as file:
Region_data = json.load(file)
except FileNotFoundError:
Region_data = {}

# New Data insert to JSON
Region_data.update(Region_dict)

# JSON file update
with open(json_path, 'w') as file:
json.dump(Region_data, file, indent=4)
Loading