Blair  - Soul Eater [파이썬 예제] Matplotlib 11- 전국의 종합병원 정보 분석 (1)

• programming language/python

[파이썬 예제] Matplotlib 11- 전국의 종합병원 정보 분석 (1)

oujin 2022. 7. 25. 14:58
728x90

CSV 예제 파일 입니다.

**입력하는 코드가 있는 파일과 같은 폴더에 위치해 있어야 합니다**

 

doctor_2019.csv
0.02MB

 

 

 

 

import csv

f = open('doctor_2019.csv', 'r', encoding='utf-8')
lines = csv.reader(f)

header = next(lines)

# 서울, 부산, 대구, 인천, 대전, 광주, 울산
area = ['서울', '부산', '대구', '인천', '대전', '광주', '울산']

doctor = ([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
           [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])

for line in lines:
    if line[0] == '서울' :
        doctor[0][0] += int(line[2])
        doctor[0][1]+= int(line[3])
        doctor[0][2] += int(line[4])
        doctor[0][3] += int(line[5])

    if line[0] == '부산' :
        doctor[1][0] += int(line[2])
        doctor[1][1]+= int(line[3])
        doctor[1][2] += int(line[4])
        doctor[1][3] += int(line[5])

    if line[0] == '대구' :
        doctor[2][0] += int(line[2])
        doctor[2][1]+= int(line[3])
        doctor[2][2] += int(line[4])
        doctor[2][3] += int(line[5])

    if line[0] == '인천' :
        doctor[3][0] += int(line[2])
        doctor[3][1]+= int(line[3])
        doctor[3][2] += int(line[4])
        doctor[3][3] += int(line[5])

    if line[0] == '대전' :
        doctor[4][0] += int(line[2])
        doctor[4][1]+= int(line[3])
        doctor[4][2] += int(line[4])
        doctor[4][3] += int(line[5])

    if line[0] == '광주' :
        doctor[5][0] += int(line[2])
        doctor[5][1]+= int(line[3])
        doctor[5][2] += int(line[4])
        doctor[5][3] += int(line[5])

    if line[0] == '울산' :
        doctor[6][0] += int(line[2])
        doctor[6][1]+= int(line[3])
        doctor[6][2] += int(line[4])
        doctor[6][3] += int(line[5])

print(header[0], header[2], header[3], header[4], header[5])

for i in range(7) :
    print(area[i], end=' ')
    for j in range(4) :
        print('%8d' % doctor[i][j], end=' ')

    print()

f.close()

 

 

 

 

 

 

 

 

 

 

 

 

출처: 예제 중심 파이썬 입문

궁금한 부분이 있으면 댓글 부탁드립니다^^

728x90