์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
- ๊นํ
- ๋ฐฑ์ค
- ์ ํ๋์ํ
- ๋ฆฌ์กํธ
- ๋์
- Titanic
- ๋จธ์ ๋ฌ๋
- ์๊ณ ๋ฆฌ์ฆ
- ํ์ดํ๋
- ๋ถ์
- ์ธํ๋ฐ
- ๋ฐ์ดํฐ
- ๋ค์ดํฐ๋ธ
- c++
- react
- ์๋๋ก์ด๋์คํ๋์ค
- ํ๊ตญ์ด์๋ฒ ๋ฉ
- nlp
- linearalgebra
- ์๋ฒ ๋ฉ
- ๋ฐ์ดํฐ๋ถ์
- Git
- AI
- native
- Kaggle
- ๊ฒฐ์ ํธ๋ฆฌ
- ๋ฐ์ดํฐ์๊ฐํ
- ์ํ์ฝ๋ฉ
- cs231n
- ๋ฅ๋ฌ๋
- Today
- Total
yeon's ๐ฉ๐ป๐ป
[๋ฐ์ดํฐ ๋ถ์] ๋ฐ์ดํฐ ์๊ฐํ | Pandas, ์์ ์์ผ ๊ทธ๋ฆผ(box-and-whisker plot) ๋ณธ๋ฌธ
[๋ฐ์ดํฐ ๋ถ์] ๋ฐ์ดํฐ ์๊ฐํ | Pandas, ์์ ์์ผ ๊ทธ๋ฆผ(box-and-whisker plot)
yeon42 2021. 7. 21. 19:19๋ฐ์ดํฐ์๊ฐํ๋ฅผ ์ํ ํฐํธ ์ค์
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. ์ต๋๊ฐ
- box plot์ ๋ํด ์ดํดํ๊ธฐ : https://boxnwhis.kr/2019/02/19/boxplot.html
- 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์ ๊ตฌํ ๋ค ์ ๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐ