파이썬

 

 

 

 

 

1.  개요

    우리 동네 인구 파악 시각화 : 
    
1. 모듈 import 및 파일 읽기

2. 전체 데이터에서 한 줄 씩 반복해 읽기 :  for문

3. 특정 지역의 데이터 확인 : if문

4. 특정 지역에 해당할 경우 인구 수를 0세부터 차례로 저장 : for문, append

5. 저장된 연령 별 인구수 데이터 시각화

 

 

 

2.  데이터 추출 및 시각화

import csv
import matplotlib.pyplot as plt

f = open('./data/age.csv', 'r', encoding='cp949')
data = csv.reader(f)



result = []
for row in data :
    if '신도림' in row[0] :
        for i in row[3:] :
            result.append(int(i))



plt.style.use('ggplot')
plt.plot(result)
plt.show()

 

 

 

3.  input함수 이용하기

f = open('./data/age.csv', 'r', encoding='cp949')
data = csv.reader(f)



result = []
name = input('인구구조가 알고 싶은 지역의 이름(읍면동 단위)을 입력하세요!').strip()

for row in data :
    if name in row[0] :
        for i in row[3:] :
            result.append(int(i))



plt.style.use('ggplot')
plt.plot(result)
plt.title(name +' 지역의 인구 구조')
plt.show()

 

 

 

4.  결론

    중년층의 인구 분포가 가장 많은 편이다.

+ Recent posts