In [1]:
import os
import numpy as np
import pandas as pd
In [2]:
os.getcwd() #현재 디렉토리 확인
Out[2]:
'/Users/limjongjun/Desktop/JayJay/Growth/Python/Class101_Pandas'
In [34]:
df4 = pd.read_csv('2016_health_checkup_1.csv')
df4.head()
Out[34]:
가입자일련번호 | 성별코드 | 연령대코드(5세단위) | 시도코드 | 신장(5Cm단위) | 체중(5Kg단위) | 허리둘레 | 시력(좌) | 시력(우) | 청력(좌) | ... | (혈청지오티)AST | (혈청지오티)ALT | 감마지티피 | 흡연상태 | 구강검진 수검여부 | 치석 | 당뇨병 의사 판정 | 고혈압 의사 판정 | 간기능 이상여부 | 알콜성간염여부 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 604509 | 1 | 12 | 41 | 165.0 | 65.0 | 7.0 | 1.2 | 1.0 | 1.0 | ... | 21.0 | 17.0 | 17.0 | 1.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 0.0 |
1 | 360197 | 2 | 17 | 43 | 130.0 | 25.0 | 50.0 | 0.3 | 0.9 | 1.0 | ... | 18.0 | 7.0 | 19.0 | 1.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 1.0 |
2 | 201061 | 2 | 17 | 45 | 150.0 | 135.0 | 51.0 | 0.5 | 0.5 | 1.0 | ... | 21.0 | 18.0 | 24.0 | 1.0 | 0 | NaN | 1.0 | 0.0 | 0.0 | 0.0 |
3 | 586237 | 2 | 12 | 41 | 145.0 | 35.0 | 51.0 | 1.5 | 0.7 | 1.0 | ... | 15.0 | 14.0 | 18.0 | 3.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 0.0 |
4 | 922457 | 2 | 9 | 11 | 150.0 | 35.0 | 51.0 | 1.2 | 1.0 | 1.0 | ... | 18.0 | 10.0 | 20.0 | 1.0 | 1 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
5 rows × 31 columns
In [40]:
df4.shape
Out[40]:
(250000, 31)
In [35]:
df4.columns
Out[35]:
Index(['가입자일련번호', '성별코드', '연령대코드(5세단위)', '시도코드', '신장(5Cm단위)', '체중(5Kg단위)',
'허리둘레', '시력(좌)', '시력(우)', '청력(좌)', '청력(우)', '수축기혈압', '이완기혈압',
'식전혈당(공복혈당)', '총콜레스테롤', '트리글리세라이드', 'HDL콜레스테롤', 'LDL콜레스테롤', '혈색소',
'요단백', '혈청크레아티닌', '(혈청지오티)AST', '(혈청지오티)ALT', '감마지티피', '흡연상태',
'구강검진 수검여부', '치석', '당뇨병 의사 판정', '고혈압 의사 판정', '간기능 이상여부', '알콜성간염여부'],
dtype='object')
In [36]:
df5 = pd.read_csv('2016_health_checkup_2.csv')
df5.head()
Out[36]:
가입자일련번호 | 성별코드 | 연령대코드(5세단위) | 시도코드 | 신장(5Cm단위) | 체중(5Kg단위) | 허리둘레 | 시력(좌) | 시력(우) | 청력(좌) | ... | (혈청지오티)AST | (혈청지오티)ALT | 감마지티피 | 흡연상태 | 구강검진 수검여부 | 치석 | 당뇨병 의사 판정 | 고혈압 의사 판정 | 간기능 이상여부 | 알콜성간염여부 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 740577 | 2 | 6 | 11 | 165.0 | 65.0 | 30.0 | 1.2 | 1.0 | 1.0 | ... | 18.0 | 10.0 | 7.0 | 1.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 0.0 |
1 | 994961 | 2 | 13 | 45 | 150.0 | 35.0 | 50.0 | 0.7 | 0.8 | 1.0 | ... | 23.0 | 12.0 | 13.0 | 1.0 | 1 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
2 | 498461 | 2 | 12 | 44 | 155.0 | 35.0 | 51.0 | 0.3 | 0.4 | 1.0 | ... | 20.0 | 8.0 | 6.0 | 1.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 1.0 |
3 | 596525 | 2 | 6 | 41 | 155.0 | 35.0 | 51.0 | 1.0 | 0.8 | 1.0 | ... | 22.0 | 11.0 | 13.0 | 1.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 0.0 |
4 | 186709 | 2 | 18 | 48 | 140.0 | 40.0 | 51.0 | 0.5 | 0.4 | 1.0 | ... | 17.0 | 9.0 | 20.0 | 1.0 | 0 | NaN | 0.0 | 1.0 | 0.0 | 0.0 |
5 rows × 31 columns
In [41]:
df5.shape
Out[41]:
(250000, 31)
In [37]:
df5.columns
Out[37]:
Index(['가입자일련번호', '성별코드', '연령대코드(5세단위)', '시도코드', '신장(5Cm단위)', '체중(5Kg단위)',
'허리둘레', '시력(좌)', '시력(우)', '청력(좌)', '청력(우)', '수축기혈압', '이완기혈압',
'식전혈당(공복혈당)', '총콜레스테롤', '트리글리세라이드', 'HDL콜레스테롤', 'LDL콜레스테롤', '혈색소',
'요단백', '혈청크레아티닌', '(혈청지오티)AST', '(혈청지오티)ALT', '감마지티피', '흡연상태',
'구강검진 수검여부', '치석', '당뇨병 의사 판정', '고혈압 의사 판정', '간기능 이상여부', '알콜성간염여부'],
dtype='object')
In [38]:
pd.concat([df4, df5]) #column이 똑같을때 위아래로 dataframe 병합(UNION)
Out[38]:
가입자일련번호 | 성별코드 | 연령대코드(5세단위) | 시도코드 | 신장(5Cm단위) | 체중(5Kg단위) | 허리둘레 | 시력(좌) | 시력(우) | 청력(좌) | ... | (혈청지오티)AST | (혈청지오티)ALT | 감마지티피 | 흡연상태 | 구강검진 수검여부 | 치석 | 당뇨병 의사 판정 | 고혈압 의사 판정 | 간기능 이상여부 | 알콜성간염여부 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 604509 | 1 | 12 | 41 | 165.0 | 65.0 | 7.0 | 1.2 | 1.0 | 1.0 | ... | 21.0 | 17.0 | 17.0 | 1.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 0.0 |
1 | 360197 | 2 | 17 | 43 | 130.0 | 25.0 | 50.0 | 0.3 | 0.9 | 1.0 | ... | 18.0 | 7.0 | 19.0 | 1.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 1.0 |
2 | 201061 | 2 | 17 | 45 | 150.0 | 135.0 | 51.0 | 0.5 | 0.5 | 1.0 | ... | 21.0 | 18.0 | 24.0 | 1.0 | 0 | NaN | 1.0 | 0.0 | 0.0 | 0.0 |
3 | 586237 | 2 | 12 | 41 | 145.0 | 35.0 | 51.0 | 1.5 | 0.7 | 1.0 | ... | 15.0 | 14.0 | 18.0 | 3.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 0.0 |
4 | 922457 | 2 | 9 | 11 | 150.0 | 35.0 | 51.0 | 1.2 | 1.0 | 1.0 | ... | 18.0 | 10.0 | 20.0 | 1.0 | 1 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
249995 | 920694 | 1 | 14 | 45 | NaN | NaN | 90.0 | 1.5 | 9.9 | 2.0 | ... | 27.0 | 19.0 | 35.0 | 1.0 | 0 | NaN | 0.0 | 1.0 | 0.0 | 0.0 |
249996 | 933726 | 1 | 11 | 45 | NaN | NaN | 86.0 | 0.9 | 0.8 | 1.0 | ... | 19.0 | 15.0 | 66.0 | 1.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 0.0 |
249997 | 950762 | 2 | 10 | 45 | NaN | NaN | 83.0 | 1.0 | 1.0 | 1.0 | ... | 15.0 | 18.0 | 27.0 | 1.0 | 0 | NaN | 1.0 | 0.0 | 0.0 | 0.0 |
249998 | 969362 | 1 | 8 | 41 | NaN | NaN | 90.0 | 1.2 | 1.2 | 1.0 | ... | 20.0 | 20.0 | 20.0 | 2.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 0.0 |
249999 | 992166 | 1 | 9 | 11 | NaN | NaN | NaN | NaN | NaN | NaN | ... | 23.0 | 35.0 | 57.0 | 2.0 | 0 | NaN | 0.0 | 0.0 | 0.0 | 0.0 |
500000 rows × 31 columns
In [42]:
for i in ['1','2','3','4'] :
print('2016_health_checkup_' + i + '.csv')
2016_health_checkup_1.csv
2016_health_checkup_2.csv
2016_health_checkup_3.csv
2016_health_checkup_4.csv
In [43]:
#방법1
df6 = pd.DataFrame()
for i in ['1','2','3','4'] :
dfn = pd.read_csv('2016_health_checkup_' + i + '.csv')
df6 = pd.concat([df6,dfn])
In [ ]:
#방법2
df6 = pd.DataFrame()
for i in range(1,5) :
dfn = pd.read_csv('2016_health_checkup_' + str(i) + '.csv')
df6 = pd.concat([df6,dfn])
In [45]:
df6.shape
Out[45]:
(1000000, 31)