Geopandas로 기본 매핑

Python으로 미국 인구조사 데이터 분석하기

Lee Hachadoorian

Asst. Professor of Instruction, Temple University

지리공간 데이터 - 추가 학습

Python으로 미국 인구조사 데이터 분석하기

지리공간 데이터 로딩

import geopandas as gpd

# Load a geospatial file geo_state = gpd.read_file("state_computer_use.gpkg")
type(geo_state)
geopandas.geodataframe.GeoDataFrame
Python으로 미국 인구조사 데이터 분석하기

Geopandas 데이터프레임

print(geo_state.columns)
Index(['state', 'postal', 'name', 'geometry', 'total', 'has_computer',
       'desktop_laptop', 'desktop_laptop_only', 'portable_device',
       'portable_device_only', 'no_computer'],
      dtype='object')
Python으로 미국 인구조사 데이터 분석하기

Geopandas 데이터프레임

print(geo_state.head())
  state postal  ... portable_device_only no_computer
0    06     CA  ...              1052406     1263635
1    08     CO  ...               148749      168639
2    11     DC  ...                23554       32916
3    16     ID  ...                46565       67454
4    17     IL  ...               415840      640062

[5 rows x 11 columns]
Python으로 미국 인구조사 데이터 분석하기

Geopandas geometry 열

print(geo_state["geometry"].head())
0    (POLYGON ((-1716661.572795197 -1091585.2669098...
1    (POLYGON ((-787764.8711845676 -679501.90042785...
2    (POLYGON ((1950824.825659711 -402441.066172522...
3    (POLYGON ((-1357254.591159301 77405.1771214068...
4    (POLYGON ((720437.1241238854 -496471.759394428...
Name: geometry, dtype: object
Python으로 미국 인구조사 데이터 분석하기

Geopandas로 플로팅

geo_state.plot()

미국 본토 지도.

Python으로 미국 인구조사 데이터 분석하기

코로플레스 지도

geo_state.plot(column = "has_computer")

미국 본토 지도. 주를 가구의 컴퓨터 보유 수로 색칠함.

Python으로 미국 인구조사 데이터 분석하기

코로플레스 지도

geo_state.plot(column = "has_computer", cmap = "YlOrRd")

미국 본토 지도. 주를 가구의 컴퓨터 보유 수로 색칠함.

Python으로 미국 인구조사 데이터 분석하기

코로플레스 지도

geo_state["pct_has_computer"] = 100 * geo_state["has_computer"]/geo_state["total"]

geo_state.plot(column = "pct_has_computer", cmap = "YlOrRd")

미국 본토 지도. 주를 가구의 컴퓨터 보유 비율로 색칠함.

Python으로 미국 인구조사 데이터 분석하기

matplotlib에서 제공하는 18개의 연속형 밝기-어둡기 컬러맵 램프.

Matplotlib 연속형 컬러맵

https://matplotlib.org/users/colormaps.html

Python으로 미국 인구조사 데이터 분석하기

연습해 봅시다!

Python으로 미국 인구조사 데이터 분석하기

Preparing Video For Download...