본문 바로가기
C.W.K.
Stream
Lesson 03 of 07 · published

Pandas DataFrame 과 Series — Labeled 테이블

~12 min · pandas, dataframe, series

Level 0구경꾼
0 XP0/47 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

NumPy 위에 Pandas 가 더하는 것

Pandas 는 Python 에서 tabular 데이터를 주무르는 표준 라이브러리야. 지금 stable 은 Pandas 3.0.5 (2026.7). 2026.1 에 나온 3.0 이 큰 고비였어 — Copy-on-Write 가 기본이 되고, PyArrow-backed string 이 주류가 되고, legacy API 가 무더기로 걷혀 나갔거든.

NumPy 가 타입 있는 수치 배열을 준다면, Pandas 는 거기에 두 가지를 얹어: label (이름 붙은 column 과 index 달린 row) 그리고 heterogeneous type (string, datetime, categorical 이 한 테이블에). 시시해 보이지 — 근데 실전에선 이게 "생 숫자" 와 "실제로 일할 수 있는 데이터" 의 차이야.

두 핵심 type

  • Series — label 붙은 column 하나. 개념적으론 NumPy 1D 배열 + index. DataFrame 의 모든 컬럼이 각각 Series 야.
  • DataFrame — 2D labeled 테이블. Column 마다 타입이 달라도 되고, row 들은 index 를 공유해.

Label 이 왜 중요해?

매출이 7번째 column 이라는 걸 외우고 싶진 않잖아. df['revenue'] 라고 쓰고 싶지. 그리고 label 은 DataFrame 사이 연산을 자동으로 줄 맞춰 줘 — DataFrame 두 개를 더하면 index 와 column label 이 맞는 자리끼리 계산되고, 안 맞는 자리는 조용한 버그가 되는 대신 NaN 으로 나타나.

Code

흔한 source 들에서 DataFrame 과 Series 만들기·python
import pandas as pd

# 1. dict-of-list 에서 (수동 구성 시 가장 흔함)
df = pd.DataFrame({
    'order_id':   ['A001', 'A002', 'A003'],
    'amount_usd': [120.50, 87.30, 215.00],
    'status':     ['shipped', 'pending', 'shipped'],
})

# 2. 단일 column 은 Series
amounts = df['amount_usd']            # Series
print(type(amounts).__name__)          # Series

# 3. 구조 살펴보기
print(df.shape)        # (3, 3)
print(df.dtypes)       # column type 들
print(df.head())       # 첫 row 들
print(df.describe())   # 수치 요약

# 4. 단일 값 select (label 기반)
print(df.loc[0, 'amount_usd'])         # 120.50

# 5. Parquet 파일에서 (현실 진입점)
# df = pd.read_parquet('orders.parquet')

# 6. Pandas 3.x 에선 PyArrow-backed string 이 더 빠르고 작음
df['status'] = df['status'].astype('string[pyarrow]')

External links

Exercise

order_id, amount_usd, order_date 세 컬럼짜리 작은 DataFrame 을 만들어. amount_usdfloat64 로, order_datedatetime64[ns] 로, order_idstring[pyarrow] 로 변환해 봐. 변환 전후로 df.dtypes 를 출력해서 schema 가 자리 잡는 감각을 느껴 봐.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.