Guidelines

Pandas둜 데이터 μš”μ•½ 톡계 κ³„μ‚°ν•˜κΈ°

λŒ€κ·œλͺ¨ λ°μ΄ν„°μ˜ 평균, ν‘œμ€€νŽΈμ°¨ 등을 ν•œ λ²ˆμ— κ³„μ‚°ν•˜λ €λ©΄ μ–΄λ–»κ²Œ ν•΄μ•Ό ν• κΉŒμš”?

각 ν•­λͺ©λ³„λ‘œ 일일이 ν•¨μˆ˜λ₯Ό μ •μ˜ν•˜κ³  κ³„μ‚°ν•˜λŠ” 것은 맀우 번거둜운 μž‘μ—…μž…λ‹ˆλ‹€.

ν•˜μ§€λ§Œ λ°μ΄ν„°ν”„λ ˆμž„μ˜ describe() λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•˜λ©΄ λ°μ΄ν„°μ˜ 개수, 평균, ν‘œμ€€νŽΈμ°¨, μ΅œμ†Ÿκ°’, μ΅œλŒ“κ°’ 등을 ν¬ν•¨ν•œ μš”μ•½ 톡계λ₯Ό ν•œ λ²ˆμ— 계산할 수 μžˆμŠ΅λ‹ˆλ‹€.

데이터 μš”μ•½ 톡계 계산
import pandas as pd data_frame = pd.DataFrame({ 'ν’ˆλͺ©': ['사과', 'λ°”λ‚˜λ‚˜', 'λ”ΈκΈ°', '포도'], '맀좜': [1000, 2000, 1500, 3000] }) # μš”μ•½ 톡계 계산 summary_stats = data_frame.describe() print(summary_stats)

data_frame.describe() μ½”λ“œλŠ” λ°μ΄ν„°ν”„λ ˆμž„μ˜ μš”μ•½ 톡계(평균, ν‘œμ€€νŽΈμ°¨, μ΅œμ†Œκ°’, μ΅œλŒ€κ°’ λ“±)λ₯Ό λ°μ΄ν„°ν”„λ ˆμž„μœΌλ‘œ λ°˜ν™˜ν•©λ‹ˆλ‹€.

describe λ©”μ„œλ“œ 좜λ ₯ κ²°κ³Ό
맀좜 count 4.000000 mean 1875.000000 std 866.025404 min 1000.000000 25% 1375.000000 50% 1750.000000 75% 2250.000000 max 3000.000000

각 ν•­λͺ©μ΄ μ˜λ―Έν•˜λŠ” λ°”λŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

  • count: λ°μ΄ν„°μ˜ 개수

  • mean: 평균값

  • std: ν‘œμ€€νŽΈμ°¨

  • min: μ΅œμ†Ÿκ°’

  • 25%, 50%, 75%: λ°±λΆ„μœ„μˆ˜(Percentile)

  • max: μ΅œλŒ“κ°’


결츑치 처리

결츑치(Missing Value)λŠ” λ°μ΄ν„°μ…‹μ—μ„œ 값이 λΉ„μ–΄ μžˆλŠ” 경우λ₯Ό μ˜λ―Έν•©λ‹ˆλ‹€.

Pandasμ—μ„œλŠ” 결츑치λ₯Ό μ²˜λ¦¬ν•˜κΈ° μœ„ν•œ λ‹€μ–‘ν•œ λ©”μ„œλ“œλ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€.

결츑치 처리 μ˜ˆμ‹œ
import pandas as pd data_frame = pd.DataFrame({ 'ν’ˆλͺ©': ['사과', 'λ°”λ‚˜λ‚˜', 'λ”ΈκΈ°', None], '맀좜': [1000, 2000, 1500, None] }) # 결츑치 확인 missing_values = data_frame.isnull() # 결츑치λ₯Ό 0으둜 λŒ€μ²΄ data_frame_filled = data_frame.fillna(0) print(data_frame_filled)
결츑치 λŒ€μ²΄ κ²°κ³Ό
ν’ˆλͺ© 맀좜 0 사과 1000.0 1 λ°”λ‚˜λ‚˜ 2000.0 2 λ”ΈκΈ° 1500.0 3 0 0.0

μ½”λ“œ μ„€λͺ…

  • data_frame.isnull() μ½”λ“œλŠ” λ°μ΄ν„°ν”„λ ˆμž„μ—μ„œ κ²°μΈ‘μΉ˜κ°€ μžˆλŠ” μœ„μΉ˜λ₯Ό True둜 ν‘œμ‹œν•œ λ°μ΄ν„°ν”„λ ˆμž„μ„ λ°˜ν™˜ν•©λ‹ˆλ‹€.

  • data_frame.fillna(0) μ½”λ“œλŠ” 결츑치λ₯Ό 0으둜 λŒ€μ²΄ν•œ λ°μ΄ν„°ν”„λ ˆμž„μ„ λ°˜ν™˜ν•©λ‹ˆλ‹€.

  • data_frame.fillna(0) λŒ€μ‹  data_frame.dropna()λ₯Ό μ‚¬μš©ν•˜λ©΄ κ²°μΈ‘μΉ˜κ°€ ν¬ν•¨λœ 행을 μ‚­μ œν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Mission
0 / 1

λ‹€μŒ λΉˆμΉΈμ— κ°€μž₯ μ μ ˆν•œ λ‹¨μ–΄λŠ” λ¬΄μ—‡μΌκΉŒμš”?

λ°μ΄ν„°ν”„λ ˆμž„μ˜ μš”μ•½ 톡계λ₯Ό κ³„μ‚°ν•˜λ €λ©΄ λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.
describe
summary
mean
aggregate

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result