Search

프로그래머스 과제 연습

JSON 파일 판다스로 읽어들이기

df = pd.read_json('/home/programmers/project/data/input/customer.json') df.head(5)
Python
복사

분석 결과 JSON 파일 형태에 맞게 저장하기

# 분석 결과 저장할 경로 만들기 import os # 디렉토리 생성 함수 def ensure_output_dir(): """출력 디렉토리가 존재하는지 확인하고, 없으면 생성""" output_dir = "./data/output" os.makedirs(output_dir, exist_ok=True) return output_dir def save_result(problem_num, result): """ 분석한 결과를 지정한 경로의 JSON 파일로 저장 Parameter: - problem_num : 문제 번호(int) - result : 저장할 결과(dict, list 등 JSON 직렬화 가능한 객체) """ output_dir = ensure_output_dir() file_path = f"{output_dir}/problem_{problem_num}.json" with open(file_path, 'w', encoding='utf-8') as f: json.dump(result, f, ensure_ascii=False, indent=2) print(f"결과가 {file_path}에 저장되었습니다.")
Python
복사

requirements.txt 파일 이해하기

사용할 패키지, 라이브러리 들을 모아두는 텍스트 파일을 따로 생성하면, 한번에 다운로드 하기 용이하다.
jupyter nbconvert pandas numpy matplotlib seaborn ...
Plain Text
복사

setup.sh 파일에 위 requirements.txt 파일 다운로드

pip3 install -r requirements.txt chmod +x setup.sh
Bash
복사

run.sh 파일에서 jupyter notebook 실행시키기

# 주피터 노트북 직접 실행 jupyter nbconvert --execute Untitled-1.ipynb --to html # 결과를 main.py 에 연동 python3 main.py # 실행 권한을 부여 chmod +x run.sh
Bash
복사