[Python, 데이터분석] 판다스 관용 해법 사용하기: Pandorable한 코드(Idiomatic Pandas: Pandorable Code), 메서드 체이닝(Method Chaining)

2021. 3. 27. 03:11 Python/파이썬 데이터 분석

 

| 판다스 관용 해법(Idiomatic Pandas)

 

판다스(Pandas)에서는 데이터 프레임을 통한 데이터 처리를 좀 더 수월하게 할 수 있도록 판다스만의 솔루션을 지원합니다. 이것을 관용 해법(Idiomatic Pandas)이라 말하고 Pandorable한 코드라고 판다스 커뮤니티에서는 이야기합니다.

 

마치 파이썬에서도 다른 언어에서는 볼 수 없는 파이썬 만의 독특한 처리방식이 있는 것처럼 판다스도 고유의 처리방법을 지원하는 거라 생각하시면 될 것 같습니다.

 

관용 해법은 높은 성능과 가독성을 동시에 지니고 있습니다. 이 방식을 채택하여 보통 파이썬언어가 지원하는 방식보다 간결하고 깔끔한 코드로 데이터를 처리하는 것이 가능해집니다.

 

| 판다스 관용해법 예제(Idiomatic Pandas Example) - 메서드 체이닝(Method Chaining)

 

판다스 관용해법 즉 Pandorable한 코드에서는 메서드 연쇄를 지원합니다. 함수형 프로그래밍에서의 해법과 거의 똑같죠. 아래는 그 예제를 모아놓은 것입니다. 이 예제들은 아래의 csv 파일을 가지고 진행하였습니다.

 

census.csv
2.06MB

 

import pandas as pd

# [3193 rows x 100 columns] 의 사이즈를 가지는 데이터프레임
df = pd.read_csv("census.csv")
print(df)
'''
      SUMLEV  REGION     ...       RNETMIG2014  RNETMIG2015
0         40       3     ...          1.724718     0.712594
1         50       3     ...          2.592270    -2.187333
2         50       3     ...         20.317142    18.293499
3         50       3     ...         -3.978583   -10.543299
4         50       3     ...          0.754533     1.107861
5         50       3     ...         -1.577232    -0.884411
6         50       3     ...         17.243790   -13.193961
7         50       3     ...          1.184103    -6.430868
8         50       3     ...         -3.912834    -2.806406
9         50       3     ...         -1.290228     2.346901
10        50       3     ...          0.230419    -2.931307
11        50       3     ...          0.957636    -1.752709
12        50       3     ...         -1.274984    -5.291205
13        50       3     ...         -8.486280    -5.411736
14        50       3     ...          5.776708     3.986270
15        50       3     ...          3.654485    -3.123961
16        50       3     ...         -0.767822     5.350738
17        50       3     ...          2.533249     0.588052
18        50       3     ...        -14.645416     2.684140
19        50       3     ...        -23.049483    -5.387581
20        50       3     ...          3.750759    -0.264121
21        50       3     ...          4.734577     5.087600
22        50       3     ...          5.593387     8.417777
23        50       3     ...         -9.503292    -1.998668
24        50       3     ...         -9.368689   -14.711389
25        50       3     ...          1.198187     0.956790
26        50       3     ...         -0.951175     2.757093
27        50       3     ...         -1.136950     1.243830
28        50       3     ...         -1.234901    -1.588308
29        50       3     ...          0.237396    -2.857058
...      ...     ...     ...               ...          ...
3163      50       2     ...          2.104796     0.059931
3164      50       2     ...          2.077633     0.593567
3165      50       2     ...         -0.134227    -0.173022
3166      50       2     ...         -4.535615    -4.024395
3167      50       2     ...         -1.545153    -3.685304
3168      50       2     ...         -5.040889    -3.414223
3169      40       4     ...         -3.727831    -2.091573
3170      50       4     ...          1.429233    -5.166460
3171      50       4     ...         -7.608378     5.513554
3172      50       4     ...         -8.509402    10.978525
3173      50       4     ...         -2.338590   -22.600668
3174      50       4     ...        -19.358233     1.126443
3175      50       4     ...          7.071547    19.309219
3176      50       4     ...        -12.013555   -13.352750
3177      50       4     ...         -5.761986   -10.635133
3178      50       4     ...         -6.224712    -5.663940
3179      50       4     ...        -10.715742     0.933652
3180      50       4     ...         -0.207819     1.673640
3181      50       4     ...          6.234414     1.662823
3182      50       4     ...         -0.110593     0.793743
3183      50       4     ...        -12.603387     7.492114
3184      50       4     ...         -5.585731     0.856839
3185      50       4     ...          5.598720     4.207414
3186      50       4     ...          4.781489    -2.198937
3187      50       4     ...        -14.409938   -20.664059
3188      50       4     ...        -14.075283   -14.070195
3189      50       4     ...         16.308671     1.520747
3190      50       4     ...        -14.740608   -12.606351
3191      50       4     ...        -18.020168     1.441961
3192      50       4     ...          1.533635     6.935294
'''
# 기존의 인덱싱 방식
df_1 = df[df["SUMLEV"]==50]
df_1.set_index(['STNAME', 'CTYNAME'], inplace=True)
df.rename(columns={"ESTIMATESBASE2010": "Estimates Base 2010"}) 
print(df_1.columns.values)
'''
['SUMLEV' 'REGION' 'DIVISION' 'STATE' 'COUNTY' 'CENSUS2010POP'
 'ESTIMATESBASE2010' 'POPESTIMATE2010' 'POPESTIMATE2011' 'POPESTIMATE2012'
 'POPESTIMATE2013' 'POPESTIMATE2014' 'POPESTIMATE2015' 'NPOPCHG_2010'
 'NPOPCHG_2011' 'NPOPCHG_2012' 'NPOPCHG_2013' 'NPOPCHG_2014'
 'NPOPCHG_2015' 'BIRTHS2010' 'BIRTHS2011' 'BIRTHS2012' 'BIRTHS2013'
 'BIRTHS2014' 'BIRTHS2015' 'DEATHS2010' 'DEATHS2011' 'DEATHS2012'
 'DEATHS2013' 'DEATHS2014' 'DEATHS2015' 'NATURALINC2010' 'NATURALINC2011'
 'NATURALINC2012' 'NATURALINC2013' 'NATURALINC2014' 'NATURALINC2015'
 'INTERNATIONALMIG2010' 'INTERNATIONALMIG2011' 'INTERNATIONALMIG2012'
 'INTERNATIONALMIG2013' 'INTERNATIONALMIG2014' 'INTERNATIONALMIG2015'
 'DOMESTICMIG2010' 'DOMESTICMIG2011' 'DOMESTICMIG2012' 'DOMESTICMIG2013'
 'DOMESTICMIG2014' 'DOMESTICMIG2015' 'NETMIG2010' 'NETMIG2011'
 'NETMIG2012' 'NETMIG2013' 'NETMIG2014' 'NETMIG2015' 'RESIDUAL2010'
 'RESIDUAL2011' 'RESIDUAL2012' 'RESIDUAL2013' 'RESIDUAL2014'
 'RESIDUAL2015' 'GQESTIMATESBASE2010' 'GQESTIMATES2010' 'GQESTIMATES2011'
 'GQESTIMATES2012' 'GQESTIMATES2013' 'GQESTIMATES2014' 'GQESTIMATES2015'
 'RBIRTH2011' 'RBIRTH2012' 'RBIRTH2013' 'RBIRTH2014' 'RBIRTH2015'
 'RDEATH2011' 'RDEATH2012' 'RDEATH2013' 'RDEATH2014' 'RDEATH2015'
 'RNATURALINC2011' 'RNATURALINC2012' 'RNATURALINC2013' 'RNATURALINC2014'
 'RNATURALINC2015' 'RINTERNATIONALMIG2011' 'RINTERNATIONALMIG2012'
 'RINTERNATIONALMIG2013' 'RINTERNATIONALMIG2014' 'RINTERNATIONALMIG2015'
 'RDOMESTICMIG2011' 'RDOMESTICMIG2012' 'RDOMESTICMIG2013'
 'RDOMESTICMIG2014' 'RDOMESTICMIG2015' 'RNETMIG2011' 'RNETMIG2012'
 'RNETMIG2013' 'RNETMIG2014' 'RNETMIG2015']
'''
print(df_1)
'''
                              SUMLEV     ...       RNETMIG2015
STNAME    CTYNAME                        ...                  
Alabama   Autauga County          50     ...         -2.187333
          Baldwin County          50     ...         18.293499
          Barbour County          50     ...        -10.543299
          Bibb County             50     ...          1.107861
          Blount County           50     ...         -0.884411
          Bullock County          50     ...        -13.193961
          Butler County           50     ...         -6.430868
          Calhoun County          50     ...         -2.806406
          Chambers County         50     ...          2.346901
          Cherokee County         50     ...         -2.931307
          Chilton County          50     ...         -1.752709
          Choctaw County          50     ...         -5.291205
          Clarke County           50     ...         -5.411736
          Clay County             50     ...          3.986270
          Cleburne County         50     ...         -3.123961
          Coffee County           50     ...          5.350738
          Colbert County          50     ...          0.588052
          Conecuh County          50     ...          2.684140
          Coosa County            50     ...         -5.387581
          Covington County        50     ...         -0.264121
          Crenshaw County         50     ...          5.087600
          Cullman County          50     ...          8.417777
          Dale County             50     ...         -1.998668
          Dallas County           50     ...        -14.711389
          DeKalb County           50     ...          0.956790
          Elmore County           50     ...          2.757093
          Escambia County         50     ...          1.243830
          Etowah County           50     ...         -1.588308
          Fayette County          50     ...         -2.857058
          Franklin County         50     ...          0.442422
...                              ...     ...               ...
Wisconsin Washburn County         50     ...         -4.995197
          Washington County       50     ...          0.059931
          Waukesha County         50     ...          0.593567
          Waupaca County          50     ...         -0.173022
          Waushara County         50     ...         -4.024395
          Winnebago County        50     ...         -3.685304
          Wood County             50     ...         -3.414223
Wyoming   Albany County           50     ...         -5.166460
          Big Horn County         50     ...          5.513554
          Campbell County         50     ...         10.978525
          Carbon County           50     ...        -22.600668
          Converse County         50     ...          1.126443
          Crook County            50     ...         19.309219
          Fremont County          50     ...        -13.352750
          Goshen County           50     ...        -10.635133
          Hot Springs County      50     ...         -5.663940
          Johnson County          50     ...          0.933652
          Laramie County          50     ...          1.673640
          Lincoln County          50     ...          1.662823
          Natrona County          50     ...          0.793743
          Niobrara County         50     ...          7.492114
          Park County             50     ...          0.856839
          Platte County           50     ...          4.207414
          Sheridan County         50     ...         -2.198937
          Sublette County         50     ...        -20.664059
          Sweetwater County       50     ...        -14.070195
          Teton County            50     ...          1.520747
          Uinta County            50     ...        -12.606351
          Washakie County         50     ...          1.441961
          Weston County           50     ...          6.935294

[3142 rows x 98 columns]
'''
'''
# 메서드 체이닝 방식 기존의 것과 비교하면 불필요한 임시 변수 생성 없이 
  간결하게 처리 가능하다.
df_1 = df[df["SUMLEV"]==50]
df_1.set_index(['STNAME', 'CTYNAME'], inplace=True)
df.rename(columns={"ESTIMATESBASE2010": "Estimates Base 2010"}) 
'''
df_2 = (df.where(df['SUMLEV']==50)
            .dropna()\
            .set_index(['STNAME','CTYNAME'])
            .rename(columns={"ESTIMATESBASE2010": "Estimates Base 2010"}))
print(df_2)
'''
                              SUMLEV     ...       RNETMIG2015
STNAME    CTYNAME                        ...                  
Alabama   Autauga County        50.0     ...         -2.187333
          Baldwin County        50.0     ...         18.293499
          Barbour County        50.0     ...        -10.543299
          Bibb County           50.0     ...          1.107861
          Blount County         50.0     ...         -0.884411
          Bullock County        50.0     ...        -13.193961
          Butler County         50.0     ...         -6.430868
          Calhoun County        50.0     ...         -2.806406
          Chambers County       50.0     ...          2.346901
          Cherokee County       50.0     ...         -2.931307
          Chilton County        50.0     ...         -1.752709
          Choctaw County        50.0     ...         -5.291205
          Clarke County         50.0     ...         -5.411736
          Clay County           50.0     ...          3.986270
          Cleburne County       50.0     ...         -3.123961
          Coffee County         50.0     ...          5.350738
          Colbert County        50.0     ...          0.588052
          Conecuh County        50.0     ...          2.684140
          Coosa County          50.0     ...         -5.387581
          Covington County      50.0     ...         -0.264121
          Crenshaw County       50.0     ...          5.087600
          Cullman County        50.0     ...          8.417777
          Dale County           50.0     ...         -1.998668
          Dallas County         50.0     ...        -14.711389
          DeKalb County         50.0     ...          0.956790
          Elmore County         50.0     ...          2.757093
          Escambia County       50.0     ...          1.243830
          Etowah County         50.0     ...         -1.588308
          Fayette County        50.0     ...         -2.857058
          Franklin County       50.0     ...          0.442422
...                              ...     ...               ...
Wisconsin Washburn County       50.0     ...         -4.995197
          Washington County     50.0     ...          0.059931
          Waukesha County       50.0     ...          0.593567
          Waupaca County        50.0     ...         -0.173022
          Waushara County       50.0     ...         -4.024395
          Winnebago County      50.0     ...         -3.685304
          Wood County           50.0     ...         -3.414223
Wyoming   Albany County         50.0     ...         -5.166460
          Big Horn County       50.0     ...          5.513554
          Campbell County       50.0     ...         10.978525
          Carbon County         50.0     ...        -22.600668
          Converse County       50.0     ...          1.126443
          Crook County          50.0     ...         19.309219
          Fremont County        50.0     ...        -13.352750
          Goshen County         50.0     ...        -10.635133
          Hot Springs County    50.0     ...         -5.663940
          Johnson County        50.0     ...          0.933652
          Laramie County        50.0     ...          1.673640
          Lincoln County        50.0     ...          1.662823
          Natrona County        50.0     ...          0.793743
          Niobrara County       50.0     ...          7.492114
          Park County           50.0     ...          0.856839
          Platte County         50.0     ...          4.207414
          Sheridan County       50.0     ...         -2.198937
          Sublette County       50.0     ...        -20.664059
          Sweetwater County     50.0     ...        -14.070195
          Teton County          50.0     ...          1.520747
          Uinta County          50.0     ...        -12.606351
          Washakie County       50.0     ...          1.441961
          Weston County         50.0     ...          6.935294

[3142 rows x 98 columns]
'''
import numpy as np
# POPESTIMATE (인수 추정) 2010~2015년도 데이터 중
# 가장 작은 값과 가장 작은 값을 반환하는 메서드
# 전 행들을 걸쳐서 진행되므로 반환값은 Series
def min_max(row):
    data = row[['POPESTIMATE2010',
                'POPESTIMATE2011',
                'POPESTIMATE2012',
                'POPESTIMATE2013',
                'POPESTIMATE2014',
                'POPESTIMATE2015']]
    return pd.Series({'min':np.min(data), 'max':np.max(data)})

# apply 메서드를 통해 df의 전 row에 대해서 min_max 메서드를 적용할 수 있다.
df_3 = df.apply(min_max, axis=1)
print(df_3)
'''
          min      max
0     4785161  4858979
1       54660    55347
2      183193   203709
3       26489    27341
4       22512    22861
5       57373    57776
6       10606    10887
7       20154    20944
8      115620   118437
9       33993    34153
10      25859    26084
11      43665    43943
12      13170    13841
13      24675    25767
14      13456    13880
15      14921    15072
16      50177    51211
17      54354    54514
18      12662    13208
19      10724    11758
20      37796    38060
21      13853    13963
22      80374    82005
23      49501    50358
24      41131    43803
25      70869    71387
26      79465    81468
27      37784    38309
28     103057   104442
29      16759    17231
...       ...      ...
3163   131967   133674
3164   390076   396488
3165    51945    52422
3166    24033    24581
3167   167059   169639
3168    73435    74807
3169   564516   586107
3170    36428    37956
3171    11672    12022
3172    46244    49220
3173    15559    15856
3174    13728    14343
3175     7114     7444
3176    40222    41129
3177    13383    13666
3178     4741     4846
3179     8552     8636
3180    92271    97121
3181    17943    18722
3182    75472    82178
3183     2475     2548
3184    28259    29237
3185     8678     8812
3186    29146    30020
3187     9899    10418
3188    43593    45162
3189    21297    23125
3190    20822    21102
3191     8316     8545
3192     7065     7234
'''
# POPESTIMATE (인수 추정) 2010~2015년도 데이터 중
# 가장 작은 값과 가장 작은 값을 의미하는 max와 min 컬럼을 만들고
# 그 값을 각각의 행들에 대해 max와 min 컬럼에 값을 넣고 그 행을 반환
def min_max(row):
    data = row[['POPESTIMATE2010',
                'POPESTIMATE2011',
                'POPESTIMATE2012',
                'POPESTIMATE2013',
                'POPESTIMATE2014',
                'POPESTIMATE2015']]
    row['max'] = np.max(data)
    row['min'] = np.min(data)
    return row

df_4 = df.apply(min_max, axis=1)
print(df_4.columns.values)
'''
['SUMLEV' 'REGION' 'DIVISION' 'STATE' 'COUNTY' 'STNAME' 'CTYNAME'
 'CENSUS2010POP' 'ESTIMATESBASE2010' 'POPESTIMATE2010' 'POPESTIMATE2011'
 'POPESTIMATE2012' 'POPESTIMATE2013' 'POPESTIMATE2014' 'POPESTIMATE2015'
 'NPOPCHG_2010' 'NPOPCHG_2011' 'NPOPCHG_2012' 'NPOPCHG_2013'
 'NPOPCHG_2014' 'NPOPCHG_2015' 'BIRTHS2010' 'BIRTHS2011' 'BIRTHS2012'
 'BIRTHS2013' 'BIRTHS2014' 'BIRTHS2015' 'DEATHS2010' 'DEATHS2011'
 'DEATHS2012' 'DEATHS2013' 'DEATHS2014' 'DEATHS2015' 'NATURALINC2010'
 'NATURALINC2011' 'NATURALINC2012' 'NATURALINC2013' 'NATURALINC2014'
 'NATURALINC2015' 'INTERNATIONALMIG2010' 'INTERNATIONALMIG2011'
 'INTERNATIONALMIG2012' 'INTERNATIONALMIG2013' 'INTERNATIONALMIG2014'
 'INTERNATIONALMIG2015' 'DOMESTICMIG2010' 'DOMESTICMIG2011'
 'DOMESTICMIG2012' 'DOMESTICMIG2013' 'DOMESTICMIG2014' 'DOMESTICMIG2015'
 'NETMIG2010' 'NETMIG2011' 'NETMIG2012' 'NETMIG2013' 'NETMIG2014'
 'NETMIG2015' 'RESIDUAL2010' 'RESIDUAL2011' 'RESIDUAL2012' 'RESIDUAL2013'
 'RESIDUAL2014' 'RESIDUAL2015' 'GQESTIMATESBASE2010' 'GQESTIMATES2010'
 'GQESTIMATES2011' 'GQESTIMATES2012' 'GQESTIMATES2013' 'GQESTIMATES2014'
 'GQESTIMATES2015' 'RBIRTH2011' 'RBIRTH2012' 'RBIRTH2013' 'RBIRTH2014'
 'RBIRTH2015' 'RDEATH2011' 'RDEATH2012' 'RDEATH2013' 'RDEATH2014'
 'RDEATH2015' 'RNATURALINC2011' 'RNATURALINC2012' 'RNATURALINC2013'
 'RNATURALINC2014' 'RNATURALINC2015' 'RINTERNATIONALMIG2011'
 'RINTERNATIONALMIG2012' 'RINTERNATIONALMIG2013' 'RINTERNATIONALMIG2014'
 'RINTERNATIONALMIG2015' 'RDOMESTICMIG2011' 'RDOMESTICMIG2012'
 'RDOMESTICMIG2013' 'RDOMESTICMIG2014' 'RDOMESTICMIG2015' 'RNETMIG2011'
 'RNETMIG2012' 'RNETMIG2013' 'RNETMIG2014' 'RNETMIG2015' 'max' 'min']  <= max, min추가
'''
print(df_4["max"])
'''
                              SUMLEV     ...       RNETMIG2015
STNAME    CTYNAME                        ...                  
Alabama   Autauga County        50.0     ...         -2.187333
          Baldwin County        50.0     ...         18.293499
          Barbour County        50.0     ...        -10.543299
          Bibb County           50.0     ...          1.107861
          Blount County         50.0     ...         -0.884411
          Bullock County        50.0     ...        -13.193961
          Butler County         50.0     ...         -6.430868
          Calhoun County        50.0     ...         -2.806406
          Chambers County       50.0     ...          2.346901
          Cherokee County       50.0     ...         -2.931307
          Chilton County        50.0     ...         -1.752709
          Choctaw County        50.0     ...         -5.291205
          Clarke County         50.0     ...         -5.411736
          Clay County           50.0     ...          3.986270
          Cleburne County       50.0     ...         -3.123961
          Coffee County         50.0     ...          5.350738
          Colbert County        50.0     ...          0.588052
          Conecuh County        50.0     ...          2.684140
          Coosa County          50.0     ...         -5.387581
          Covington County      50.0     ...         -0.264121
          Crenshaw County       50.0     ...          5.087600
          Cullman County        50.0     ...          8.417777
          Dale County           50.0     ...         -1.998668
          Dallas County         50.0     ...        -14.711389
          DeKalb County         50.0     ...          0.956790
          Elmore County         50.0     ...          2.757093
          Escambia County       50.0     ...          1.243830
          Etowah County         50.0     ...         -1.588308
          Fayette County        50.0     ...         -2.857058
          Franklin County       50.0     ...          0.442422
...                              ...     ...               ...
Wisconsin Washburn County       50.0     ...         -4.995197
          Washington County     50.0     ...          0.059931
          Waukesha County       50.0     ...          0.593567
          Waupaca County        50.0     ...         -0.173022
          Waushara County       50.0     ...         -4.024395
          Winnebago County      50.0     ...         -3.685304
          Wood County           50.0     ...         -3.414223
Wyoming   Albany County         50.0     ...         -5.166460
          Big Horn County       50.0     ...          5.513554
          Campbell County       50.0     ...         10.978525
          Carbon County         50.0     ...        -22.600668
          Converse County       50.0     ...          1.126443
          Crook County          50.0     ...         19.309219
          Fremont County        50.0     ...        -13.352750
          Goshen County         50.0     ...        -10.635133
          Hot Springs County    50.0     ...         -5.663940
          Johnson County        50.0     ...          0.933652
          Laramie County        50.0     ...          1.673640
          Lincoln County        50.0     ...          1.662823
          Natrona County        50.0     ...          0.793743
          Niobrara County       50.0     ...          7.492114
          Park County           50.0     ...          0.856839
          Platte County         50.0     ...          4.207414
          Sheridan County       50.0     ...         -2.198937
          Sublette County       50.0     ...        -20.664059
          Sweetwater County     50.0     ...        -14.070195
          Teton County          50.0     ...          1.520747
          Uinta County          50.0     ...        -12.606351
          Washakie County       50.0     ...          1.441961
          Weston County         50.0     ...          6.935294

[3142 rows x 98 columns]
'''
# lambda로 익명함수를 만들어서 apply에 적용가능
# lambda에 들어가는 입력값은 각각의 행들이 들어감
rows = ['POPESTIMATE2010',
        'POPESTIMATE2011',
        'POPESTIMATE2012',
        'POPESTIMATE2013',
        'POPESTIMATE2014',
        'POPESTIMATE2015']
df_5 = df.apply(lambda x: np.max(x[rows]), axis=1)
print(df_5)
'''
                              SUMLEV     ...       RNETMIG2015
STNAME    CTYNAME                        ...                  
Alabama   Autauga County        50.0     ...         -2.187333
          Baldwin County        50.0     ...         18.293499
          Barbour County        50.0     ...        -10.543299
          Bibb County           50.0     ...          1.107861
          Blount County         50.0     ...         -0.884411
          Bullock County        50.0     ...        -13.193961
          Butler County         50.0     ...         -6.430868
          Calhoun County        50.0     ...         -2.806406
          Chambers County       50.0     ...          2.346901
          Cherokee County       50.0     ...         -2.931307
          Chilton County        50.0     ...         -1.752709
          Choctaw County        50.0     ...         -5.291205
          Clarke County         50.0     ...         -5.411736
          Clay County           50.0     ...          3.986270
          Cleburne County       50.0     ...         -3.123961
          Coffee County         50.0     ...          5.350738
          Colbert County        50.0     ...          0.588052
          Conecuh County        50.0     ...          2.684140
          Coosa County          50.0     ...         -5.387581
          Covington County      50.0     ...         -0.264121
          Crenshaw County       50.0     ...          5.087600
          Cullman County        50.0     ...          8.417777
          Dale County           50.0     ...         -1.998668
          Dallas County         50.0     ...        -14.711389
          DeKalb County         50.0     ...          0.956790
          Elmore County         50.0     ...          2.757093
          Escambia County       50.0     ...          1.243830
          Etowah County         50.0     ...         -1.588308
          Fayette County        50.0     ...         -2.857058
          Franklin County       50.0     ...          0.442422
...                              ...     ...               ...
Wisconsin Washburn County       50.0     ...         -4.995197
          Washington County     50.0     ...          0.059931
          Waukesha County       50.0     ...          0.593567
          Waupaca County        50.0     ...         -0.173022
          Waushara County       50.0     ...         -4.024395
          Winnebago County      50.0     ...         -3.685304
          Wood County           50.0     ...         -3.414223
Wyoming   Albany County         50.0     ...         -5.166460
          Big Horn County       50.0     ...          5.513554
          Campbell County       50.0     ...         10.978525
          Carbon County         50.0     ...        -22.600668
          Converse County       50.0     ...          1.126443
          Crook County          50.0     ...         19.309219
          Fremont County        50.0     ...        -13.352750
          Goshen County         50.0     ...        -10.635133
          Hot Springs County    50.0     ...         -5.663940
          Johnson County        50.0     ...          0.933652
          Laramie County        50.0     ...          1.673640
          Lincoln County        50.0     ...          1.662823
          Natrona County        50.0     ...          0.793743
          Niobrara County       50.0     ...          7.492114
          Park County           50.0     ...          0.856839
          Platte County         50.0     ...          4.207414
          Sheridan County       50.0     ...         -2.198937
          Sublette County       50.0     ...        -20.664059
          Sweetwater County     50.0     ...        -14.070195
          Teton County          50.0     ...          1.520747
          Uinta County          50.0     ...        -12.606351
          Washakie County       50.0     ...          1.441961
          Weston County         50.0     ...          6.935294

[3142 rows x 98 columns]
'''

 

참고자료 : https://www.coursera.org/learn/python-data-analysis

출처: https://engkimbs.tistory.com/690?category=763908 [새로비]