๊ด€๋ฆฌ ๋ฉ”๋‰ด

yeon's ๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป

[๋ฐ์ดํ„ฐ ๋ถ„์„] ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™” | Pandas, ์ƒ์ž ์ˆ˜์—ผ ๊ทธ๋ฆผ(box-and-whisker plot) ๋ณธ๋ฌธ

Computer ๐Ÿ’ป/๋ฐ์ดํ„ฐ ๋ถ„์„

[๋ฐ์ดํ„ฐ ๋ถ„์„] ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™” | Pandas, ์ƒ์ž ์ˆ˜์—ผ ๊ทธ๋ฆผ(box-and-whisker plot)

yeon42 2021. 7. 21. 19:19
728x90
๋ฐ์ดํ„ฐ์‹œ๊ฐํ™”๋ฅผ ์œ„ํ•œ ํฐํŠธ ์„ค์ •
import matplotlib.pyplot as plt

# for Window User
plt.rc("font", family="Malgun Gothic")
# for Mac User
plt.rc("font", family="AppleGothic")

 

 

 

Pandas๋กœ ์‹œ๊ฐํ™” ํ•˜๊ธฐ
  • Pandas

- ๋ฏธ๋ฆฌ ๊ณ„์‚ฐ์„ ํ•˜๊ณ  ๊ทธ๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์— seaborn๋ณด๋‹ค ์†๋„๊ฐ€ ๋” ๋น ๋ฅด๋‹ค.

 

g = df_last.groupby(["์ง€์—ญ๋ช…"])["ํ‰๋‹น๋ถ„์–‘๊ฐ€๊ฒฉ"].mean().sort_values(ascending=False)
g.plot.bar(rot=0, figsize=(10, 3))

: ์ง€์—ญ๋ช…์œผ๋กœ ๋ถ„์–‘๊ฐ€๊ฒฉ์˜ ํ‰๊ท ์„ ๊ตฌํ•˜๊ณ  ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„(bar)๋กœ ์‹œ๊ฐํ™” ํ•˜๊ธฐ

  - g.plot.bar()

  - g.plot(kind="bar")

- rot : ๊ธ€์ž์˜ ๊ฐ๋„(?) ์กฐ์ ˆ

  - rot=0 : ๊ธ€์”จ ๊ฐ€๋กœ๋กœ ๋˜‘๋ฐ”๋กœ

- figsize : ๊ทธ๋ž˜ํ”„ ํฌ๊ธฐ ์กฐ์ ˆ

 

 

df_last.groupby(["์ „์šฉ๋ฉด์ "])["ํ‰๋‹น๋ถ„์–‘๊ฐ€๊ฒฉ"].mean().plot.bar()

: ์ „์šฉ๋ฉด์ ๋ณ„ ๋ถ„์–‘๊ฐ€๊ฒฉ์˜ ํ‰๊ท  ๊ตฌํ•˜๊ณ , ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„(bar)๋กœ ์‹œ๊ฐํ™” ํ•˜๊ธฐ

 

 

df_last.groupby(["์—ฐ๋„"])["ํ‰๋‹น๋ถ„์–‘๊ฐ€๊ฒฉ"].mean().plot()

: ์—ฐ๋„๋ณ„ ๋ถ„์–‘๊ฐ€๊ฒฉ์˜ ํ‰๊ท  ๊ตฌํ•˜๊ณ , ์„  ๊ทธ๋ž˜ํ”„๋กœ ์‹œ๊ฐํ™” ํ•˜๊ธฐ

  - ๊ทธ๋ž˜ํ”„์˜ default ๊ฐ’์€ ์„  ๊ทธ๋ž˜ํ”„ (line plot)

 

 

 


 

 

box-and-whisker plot | diagram
  • ์ƒ์ž ์ˆ˜์—ผ ๊ทธ๋ฆผ (box-and-whisker plot/diagram)

- ์ˆ˜์น˜์  ์ž๋ฃŒ๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๊ทธ๋ž˜ํ”„

- ๊ฐ€๊ณตํ•˜์ง€ ์•Š์€ ์ž๋ฃŒ ๊ทธ๋Œ€๋กœ๋ฅผ ์ด์šฉํ•ด ๊ทธ๋ฆฐ ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ์ž๋ฃŒ๋กœ๋ถ€ํ„ฐ ์–ป์–ด๋‚ธ ํ†ต๊ณ„๋Ÿ‰์ธ 5๊ฐ€์ง€ ์š”์•ฝ ์ˆ˜์น˜๋ฅผ ๊ฐ€์ง€๊ณ  ๊ทธ๋ฆฐ ๊ฒƒ

 

https://ko.wikipedia.org/wiki/์ƒ์ž_์ˆ˜์—ผ_๊ทธ๋ฆผ

 

์ƒ์ž ์ˆ˜์—ผ ๊ทธ๋ฆผ - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

๊ธฐ์ˆ  ํ†ต๊ณ„ํ•™์—์„œ '์ƒ์ž ์ˆ˜์—ผ ๊ทธ๋ฆผ'(box-and-whisker plot, box-and-whisker diagram) ๋˜๋Š” '์ƒ์ž ๊ทธ๋ฆผ'(box plot, boxplot)์€ ์ˆ˜์น˜์  ์ž๋ฃŒ๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๊ทธ๋ž˜ํ”„์ด๋‹ค. ์ด ๊ทธ๋ž˜ํ”„๋Š” ๊ฐ€๊ณตํ•˜์ง€ ์•Š์€ ์ž๋ฃŒ ๊ทธ๋Œ€๋กœ๋ฅผ ์ด์šฉํ•˜

ko.wikipedia.org

 

 

  • 5๊ฐ€์ง€ ์š”์•ฝ ์ˆ˜์น˜

1. ์ตœ์†Ÿ๊ฐ’

2. ์ œ 1์‚ฌ๋ถ„์œ„ ์ˆ˜

3. ์ œ 2์‚ฌ๋ถ„์œ„ ์ˆ˜ (=์ค‘์•™๊ฐ’)

4. ์ œ 3์‚ฌ๋ถ„์œ„ ์ˆ˜

5. ์ตœ๋Œ“๊ฐ’

 

 

- bar plot์— ๋น„ํ•ด ๊ฐ’์„ ๋” ์ž์„ธํžˆ ํ‘œํ˜„ ํ•  ์ˆ˜ ์žˆ๋‹ค. (5๊ฐ€์ง€ ์ˆ˜์น˜)

- ์ด์ƒ์น˜๋„ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

 

 

๋ฐ•์Šค ํ”Œ๋กฏ์— ๋Œ€ํ•˜์—ฌ

๋ฐ•์Šคํ”Œ๋กฏ์ด ์–ด๋–ป๊ฒŒ ๊ทธ๋ ค์ง€๋Š”์ง€, ์™œ ๊ทธ๋ ‡๊ฒŒ ๊ทธ๋ ค์ง€๊ฒŒ ๋˜์—ˆ๋Š”์ง€, ์–ด๋–ค ์˜๋ฏธ๋“ค์„ ์ฝ์–ด๋‚ผ ์ˆ˜ ์žˆ๋Š”์ง€ ๋“ฑ์„ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

boxnwhis.kr

 

 

 

 

 

df_last.pivot_table(index="์›”", columns="์—ฐ๋„", values="ํ‰๋‹น๋ถ„์–‘๊ฐ€๊ฒฉ").plot.box()

: index๋ฅผ ์›”, columns๋ฅผ ์—ฐ๋„๋กœ ๊ตฌํ•˜๊ณ , ํ‰๋‹น๋ถ„์–‘๊ฐ€๊ฒฉ์œผ๋กœ pivot_table์„ ๊ตฌํ•ด ์ƒ์ž์ˆ˜์—ผ๊ทธ๋ฆผ ๊ทธ๋ฆฌ๊ธฐ

- index ๊ฐ’ ๋ณ„๋กœ ๋‚˜๋ˆ ์ง

 

df_last.pivot_table(index="์›”", columns=["์—ฐ๋„", "์ „์šฉ๋ฉด์ "], values="ํ‰๋‹น๋ถ„์–‘๊ฐ€๊ฒฉ")

: columns์— ์—ฐ๋„, ์ „์šฉ๋ฉด์ ์„ ์ถ”๊ฐ€ํ•ด pivot_table์„ ๋งŒ๋“ค๊ณ  ์‹œ๊ฐํ™” ํ•˜๊ธฐ

 

df_last.pivot_table(index="์—ฐ๋„", columns="์›”", values="ํ‰๋‹น๋ถ„์–‘๊ฐ€๊ฒฉ")

: index๋ฅผ ์—ฐ๋„, columns๋ฅผ ์›”๋กœ ๊ตฌํ•˜๊ณ , ํ‰๋‹น๋ถ„์–‘๊ฐ€๊ฒฉ์„ pivot_table์„ ๊ตฌํ•œ ๋’ค ์„ ๊ทธ๋ž˜ํ”„ ๊ทธ๋ฆฌ๊ธฐ

Comments