- 목차
- 데이터 설명
- 분석 과제
- 데이터 출처
- 데이터 전처리
* 데이터 설명
235개의 국가 및 독립도시에 대한 인구 관련 지표로 아래와 같은 요소로 구성
- Country (국가 or 보호령)
- Population_2020 (2020년 기준 인구수)
- Yearly_Change (%)(전년기준 변화율)
- Net_Change(변화된 순 인구수)
- Density (1Km 제곱당 인구수)
- Land Area(토지면적)
- Migrants (이민자 수)
- Fert_Rage (출산률)
- Median_Age (평균 연령)
- Urban_Pop (%) (도시인구 비중)
- World_Share (%)(인구 비중)
- 분석 과제
위 데이터를 통해 아래와 같은 궁금증을 풀어보자.
1. 전세계 인구수 파악하기
2. 전세계 출산율 파악하기
3. 전세계 중간 나이 파악하기
4. 전세계 인구 증감 비율 확인하기
5. 1Km제곱당 인구밀도 확인하기
6. 세계 국가면적 파악하기
7. 인구이동 파악하기
8. 도시 인구 비중 파악하기
- 데이터 출처
※ 유의사항!
데이터의 출처는 아래의 사이트로 각각의 수치들은 어느 정도의 신뢰성은 있지만 하나씩 꼼꼼하게 따져보면 실제와 다른 데이터도 꽤 많이 포함되어 있으므로 유의하길 바랍니다.
아래 사이트에서 스크랩한 자료를 기반으로 데이터 분석을 진행하였으며 분석 과정 중에 실제와 다른 값이 포함되는 경우도 있어서 이를 수정하여 분석을 진행하였습니다.
ex) 국가 면적 관련 크기 수정 (한국, 러시아, 중국, 미국, 캐나다만 수정)
https://www.worldometers.info/world-population/population-by-country/ - WorldoMeters
Population by Country (2021) - Worldometer
Countries in the world by population (2021) This list includes both countries and dependent territories. Data based on the latest United Nations Population Division estimates. Click on the name of the country or dependency for current estimates (live popul
www.worldometers.info
- 데이터 전처리
전처리 과정
1. 칼럼 명 수정하기
2. Nan 값 처리하기 - 각 칼럼의 평균값으로 대체
3. % 특수 문자 제거하기 - re 모듈
4. 문자열 -> 숫자형으로 변환
- 코드
## import modules
import pandas as pd
import numpy as np
import re
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib import font_manager,rc
import matplotlib
## matplot 한글
font_path = 'C:\\Windows\\Fonts\\gulim.ttc'
font_name = font_manager.FontProperties(fname=font_path).get_name() #폰트 이름 얻어오기
matplotlib.rc('font',family=font_name) #font 설정
## upload data
data = pd.read_csv("C:\\Users\\USER\\Desktop\\Data\\World_Population.csv", encoding='cp949')
# 칼럼명 수정하기
data.columns=['Country','Population','Yearly Change','Net Change','Density','Land Area','Migrants','Fert Rate','Median Age','Urban Pop','World Share']
## % 값을 제거
def per_removal(cols):
return re.sub(r'[%]','',cols)
## Nan 값이 있는 칼럼 확인하기
data.isnull().sum()
## Nan 값을 제외
temp = data
temp=temp.dropna()
temp['Urban Pop'] = temp['Urban Pop'].apply(per_removal)
temp['World Share'] = temp['World Share'].apply(per_removal)
## 문자형 -> 숫자형 변경
temp[['Urban Pop','World Share']] = temp[['Urban Pop','World Share']].apply(pd.to_numeric)
## Nan 값을 mean 값으로 대체하기
urban_mean = int(temp['Urban Pop'].mean())
urban_mean
migrants_mean = int(temp['Migrants'].mean())
migrants_mean
fert_mean = int(temp['Fert Rate'].mean())
fert_mean
median_age_mean = int(temp['Median Age'].mean())
median_age_mean
data['Urban Pop'] = data['Urban Pop'].fillna(str(urban_mean))
data['Migrants'] = data['Migrants'].fillna(migrants_mean)
data['Fert Rate'] = data['Fert Rate'].fillna(fert_mean)
data['Median Age'] = data['Median Age'].fillna(median_age_mean)
## %를 제거하기
data['Yearly Change'] = data['Yearly Change'].apply(per_removal)
data['Urban Pop'] = data['Urban Pop'].apply(per_removal)
data['World Share'] = data['World Share'].apply(per_removal)
## 문자형 -> 숫자형 자료로 변환
data[['Yearly Change','Urban Pop','Fert Rate', 'Median Age', 'World Share' ]] = data[['Yearly Change','Urban Pop','Fert Rate', 'Median Age', 'World Share']].apply(pd.to_numeric)
## 전처리 완료된 데이터 csv 파일로 저장
data.to_csv('C:\\Users\\USER\\Desktop\\Data\\world_population_2020.csv', encoding='utf-8', index=False)
'데이터 분석' 카테고리의 다른 글
2020년 전세계 인구 지표 (3) - 출산율 분포 파악하기 (0) | 2021.12.10 |
---|---|
2020년 전세계 인구 지표 (2) - 인구 수 파악하기 (0) | 2021.12.09 |
서울 생활이동 데이터 분석 (3) - QGIS (0) | 2021.11.17 |
서울 생활이동 데이터 분석 (2) (0) | 2021.11.17 |
서울 생활이동 데이터 분석 (1) (0) | 2021.11.15 |
댓글