Pandas 1

중급 Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

표 형식의 데이터 세트 예시

ch_2_3_slides.003.png

중급 Python

표 형식의 데이터 세트 예시

ch_2_3_slides.005.png

중급 Python

표 형식의 데이터 세트 예시

ch_2_3_slides.007.png

중급 Python

Python의 데이터 세트

  • 2D NumPy 배열?{{1}} - 하나의 데이터 타입
중급 Python

Python의 데이터 세트

ch_2_3_slides.012.png

중급 Python

Python의 데이터 세트

ch_2_3_slides.013.png

  • pandas!
    • 고수준 조작 도구
    • 웨스 맥키니
    • NumPy 기반
    • DataFrame
중급 Python

DataFrame

brics
         country    capital    area  population
BR        Brazil   Brasilia   8.516      200.40
RU        Russia     Moscow  17.100      143.50
IN         India  New Delhi   3.286     1252.00
CH         China    Beijing   9.597     1357.00
SA  South Africa   Pretoria   1.221       52.98
중급 Python

딕셔너리로 DataFrame 만들기

dict = { 
    "country":["Brazil", "Russia", "India", "China", "South Africa"],
    "capital":["Brasilia", "Moscow", "New Delhi", "Beijing", "Pretoria"],
       "area":[8.516, 17.10, 3.286, 9.597, 1.221]
 "population":[200.4, 143.5, 1252, 1357, 52.98] }
  • 키(열 레이블)
import pandas as pd

brics = pd.DataFrame(dict)
중급 Python

딕셔너리로 DataFrame 만들기(2)

brics
     area    capital       country  population
0   8.516   Brasilia        Brazil      200.40
1  17.100     Moscow        Russia      143.50
2   3.286  New Delhi         India     1252.00
3   9.597    Beijing         China     1357.00
4   1.221   Pretoria  South Africa       52.98
brics.index = ["BR", "RU", "IN", "CH", "SA"]

brics
      area    capital       country  population
BR   8.516   Brasilia        Brazil      200.40
RU  17.100     Moscow        Russia      143.50
IN   3.286  New Delhi         India     1252.00
CH   9.597    Beijing         China     1357.00
SA   1.221   Pretoria  South Africa       52.98
중급 Python

CSV 파일로 DataFrame 만들기

brics.csv

,country,capital,area,population
BR,Brazil,Brasilia,8.516,200.4
RU,Russia,Moscow,17.10,143.5
IN,India,New Delhi,3.286,1252
CH,China,Beijing,9.597,1357
SA,South Africa,Pretoria,1.221,52.98
  • CSV = 쉼표로 구분된 값
중급 Python

CSV 파일로 DataFrame 만들기

  • brics.csv
,country,capital,area,population
BR,Brazil,Brasilia,8.516,200.4
RU,Russia,Moscow,17.10,143.5
IN,India,New Delhi,3.286,1252
CH,China,Beijing,9.597,1357
SA,South Africa,Pretoria,1.221,52.98
brics = pd.read_csv("path/to/brics.csv")

brics
  Unnamed: 0       country    capital    area  population
0         BR        Brazil   Brasilia   8.516      200.40
1         RU        Russia     Moscow  17.100      143.50
2         IN         India  New Delhi   3.286     1252.00
3         CH         China    Beijing   9.597     1357.00
4         SA  South Africa   Pretoria   1.221       52.98
중급 Python

CSV 파일로 DataFrame 만들기

brics = pd.read_csv("path/to/brics.csv", index_col = 0)

brics
         country  population      area    capital
BR        Brazil         200   8515767   Brasilia
RU        Russia         144  17098242     Moscow
IN         India        1252   3287590  New Delhi
CH         China        1357   9596961    Beijing
SA  South Africa          55   1221037   Pretoria
중급 Python

연습해봅시다!

중급 Python

Preparing Video For Download...