pandas

Pandas

νŒλ‹€μŠ€λŠ” νŒŒμ΄μ¬μ—μ„œ κ°€μž₯ 널리 μ‚¬μš©λ˜λŠ” 데이터 뢄석 라이브러리둜 Data Frame κ³Ό Series 자료ꡬ쑰λ₯Ό μ‚¬μš©ν•œλ‹€.

Series

One-dimensional ndarray with axis labels (including time series).

Ex) df[ν”Όμ²˜]

Attributes

Name

description

Series.index

The index (axis labels) of the Series

Methods

name

Description

Series.tolist()

Return a list of the values

Series.iteritems()

Lazily iterate over (index, value) tuples. Lazily ν•˜κ²Œ iterate ν•œλ‹€λŠ” 것은 for λ¬Έ 같은 λ°˜λ³΅λ¬Έμ—μ„œ Series 의 (idx, val) νŠœν”Œμ„ ν•˜λ‚˜μ”© κΊΌλ‚΄μ“°κΈ° μœ„ν•¨μΈ 것 row κ°€ index κ°€ λ˜λŠ” Series νŠΉμ„±μƒ for idx, val in enumerate(): μ—μ„œλŠ” row μ“Έ 수 μ—†κΈ° λ•Œλ¬Έμ— ν•„μš”ν•œ 것 κ°™λ‹€.

Series.unique()

Return unique values of Series object. type 은 λ„˜νŒŒμ΄λ°°μ—΄μ΄λ‹€.

DataFrame

Two-dimensional, size-mutable, potentially heterogeneous tabular data.

μΈλ±μŠ€μ— 쑰건문을 λ„£μ–΄μ„œ 인덱슀 ν•  수 있음 Ex) results = chipo_orderid_group[chipo_orderid_group.item_price >= 10]

Getting data in/out

csv

  • Writing to a csv file

  • Reading frome a csv file

Attributes

Ref) df[ν”Όμ²˜] == df.ν”Όμ²˜

DafaFrame 은 인덱싱 μ•ˆμ— 쑰건문을 넣을 수 μžˆλ‹€. Ex) df[df.ν”Όμ²˜ >= num] => df 쀑 쑰건문에 ν•΄λ‹Ήν•˜λŠ” row 만 μ·¨ν•˜λŠ” df λ₯Ό λ°˜ν™˜

Name

description

df.shape

Return a tuple representing the dimensionality of the DataFrame. => (how many row, how many ν”Όμ²˜)

df.index

return index (row labels) of the df RangeIndex(start = [num], stop = [num], step= [num])

Methods

Command

description

df.value_counts([subset, normalize, ...])

Return a Series containing counts of unique rows in the DataFrame. 같은 행이 λͺ‡κ°œμΈμ§€ 갯수의 λ‚΄λ¦Όμ°¨μˆœ Series λ₯Ό λ°˜ν™˜ν•˜λ©°, μˆœμ„œ 숫자 뿐만 μ•„λ‹ˆλΌ, ν•΄λ‹Ή ν–‰μ˜ μ΄λ¦„μœΌλ‘œ 인덱싱할 수 μžˆλ‹€. 인자둜 ν”Όμ²˜λ₯Ό 써도 되고 df[ν”Όμ²˜] 둜 μΈλ±μ‹±ν•œ df 에 μΈμžμ—†λŠ” λ§€μ„œλ“œλ₯Ό 걸어도 λœλ‹€.

df.info()

Print a concise summary of a DataFrame.

df.head([n])

Return the first n rows

Group DataFrame using a mapper or by a Series of columns.

df.apply()

이건 뭐... apply μ•ˆμ—μ„œ μ μš©λ˜λŠ” ν•¨μˆ˜κ°€ 더 μ€‘μš”ν•œλ° λ”°λ‘œ μ¨μ•Όν•˜λ‚˜ 고민이넀 λ°μ΄ν„°μ „μ²˜λ¦¬λ₯Ό μœ„ν•΄ μ‚¬μš©ν•¨

df.sort_values([by, ascending...])

Sort by the values along either axis.

Df.drop_duplicates()

Return DataFrame with duplicate rows removed.

df.fillna()c

κ²°μΈ‘μΉ˜λ“€μ„ 인자 κ°’μœΌλ‘œ λ°”κΏ”μ€€λ‹€.

df.corr()

상관관계 ν•¨μˆ˜ 인자둜 method κ°€ 있고 'pearson' 을 많이 μ“΄λ‹€.

Property

Command

description

df.iloc[]

μœ„μΉ˜ μ •μˆ˜λ₯Ό 기반으둜 μΈλ±μ‹±ν•œλ‹€ [] λŠ” μ—΄(column) 을 μ„ νƒν•˜μ§€λ§Œ, .loc, .iloc 은 ν–‰(row) λ₯Ό μ„ νƒν•œλ‹€

DataFrame.groupby

df.groupby([by]) ν•¨μˆ˜μ— μ˜ν•΄ μƒμ„±λœ 객체. 인자 λ³„λ‘œ κ·Έλ£Ήν™”λ˜μ–΄ 있으며, 인자 λ³„λ‘œ 그룹된 κ²ƒλ“€μ˜ μ–΄λ–€ ν”Όμ²˜λ₯Ό μ–΄λ–€ μ—°μ‚°ν•œ κ²°κ³Όλ₯Ό value 둜 κ°€μ§ˆ 것인지

df.groupby('κ·Έλ£Ήν™”μΈμž')[λŒ€μƒ ν”Όμ²˜].μ–΄λ–€μ—°μ‚°ν•¨μˆ˜()

Methods

name

description

Count()

κ·Έλƒ₯ 갯수 μ…ˆ (쀑볡에 상관없이 κ·Έλƒ₯ 행이 λͺ‡κ°œμΈμ§€ μ„ΈλŠ” λ“―?)

Sum()

λŒ€μƒ ν”Όμ²˜μ˜ val 듀을 λˆ„μ  ν•© 함

Numpy

array κ°œλ…μœΌλ‘œ λ³€μˆ˜λ₯Ό μ‚¬μš©ν•œλ‹€. λ„˜νŒŒμ΄ 배열은 데이터 λΆ„μ„μ—μ„œ μ“°λŠ” κΈ°λ³Έ 자료ꡬ쑰. 벑터, ν–‰λ ¬ λ“±μ˜ 연산을 쉽고 λΉ λ₯΄κ²Œ ν•˜κΈ° μœ„ν•΄ λ§Œλ“€μ–΄μ§„ 파이썬 라이브러리

Matplotlib

데이터λ₯Ό κ·Έλž˜ν”„λ‘œ μ‹œκ°ν™”ν•΄μ£ΌλŠ” 라이브러리

matplotlib.pyplot

matplotlib.pyplot is a state-based interface to matplotlib

state-based 방식 (interface) κ³Ό object-oriented 방식이 μžˆλŠ”λ° 링크arrow-up-right 에 차이점을 μ„€λͺ…ν•΄μ£ΌλŠ”λ° 아직 감이 μž‘νžˆλŠ” 정도일 뿐, μ™„λ²½ν•˜κ²Œ μ΄ν•΄λŠ” μ•ˆ 됨

Last updated