[python/ํ์ด์ฌ] Matplotlib (2) - ๋ง๋ ํ๋กฏ(Bar plot), ์ฐ์ ๋(scatter plot)
Matplotlib ๋ง๋ ํ๋กฏ(Bar plot) ๋ฒ์ฃผ๊ฐ ์๋ ๋ฐ์ดํฐ ๊ฐ์ ์ง์ฌ๊ฐํ์ ๋ง๋๋ก ํํํ๋ ๊ทธ๋ํ Matplotlib.pyplot๋ชจ๋์ bar() ํจ์๋ฅผ ์ด์ฉํด์ ๋ง๋ ๊ทธ๋ํ๋ก ํํ plt.bar(x, y) height = [np.random.randn()*i for i in range(1,6)] height [0.6588962912818714, 2.200417941881023, 7.807284960756258, -5.858111045118885, -2.4625299259159497] names = ['A','B','C','D','E'] y_pos = np.arange(len(names)) y_pos array([0, 1, 2, 3, 4]) plt.bar(y_pos, height) plt.xti..
2022. 8. 4.
[python/ํ์ด์ฌ] subplot / subplots ๋ฅผ ์ด์ฉํ ์ฌ๋ฌ๊ฐ์ ์ฐจํธ ๊ทธ๋ฆฌ๊ธฐ
subplot / subplots ๋ฅผ ์ด์ฉํ ์ฌ๋ฌ๊ฐ์ ์ฐจํธ ๊ทธ๋ฆฌ๊ธฐ Subplot import matplotlib.pyplot as plt -๋ฌธ์ : data1(x : 1, 2, 3; y : 1, 2, 3)๊ณผ data2(x : 1, 2, 3; y : 1, 100, 200)์ ๊ทธ๋ํ๋ก ์ถ๋ ฅํ๊ธฐ x1 = [1, 2, 3] y1 = [1, 2, 3] x2 = [1, 2, 3] y2 = [1, 100, 200] subplot์ ์ด์ฉํ ํด๊ฒฐ subplot()ํจ์๋ ์ฌ๋ฌ ๊ฐ์ ๊ทธ๋ํ๋ฅผ ํ๋์ ๊ทธ๋ฆผ์ ๋ํ๋๋๋ก ํ๋ค. subplot(ํ์ ์, ์ด์ ์, ํด๋น ๊ทธ๋ํ๊ฐ ๊ทธ๋ ค์ง ์์น) plt.subplot(1, 2, 1) plt.plot(x1, y1) plt.title('data1') plt.subplot(1, 2, 2)..
2022. 8. 2.
[python/ํ์ด์ฌ] ํผ๋ฒํ
์ด๋ธ(pivot table)
ํผ๋ฒํ
์ด๋ธ import pandas as pd import numpy as np -๋ฌธ์ : ๋ค์ ๋ฐ์ดํฐ ํ๋ ์์ A ์๋น์ค์ ์๋ณ ํํด ํ์์๋ฅผ ๊ฐ์
์๋ณ๋ก ๋ถ๋ฅํด ๋์ ๊ฒ์ด๋ค. ์ด ๋ฐ์ดํฐ ํ๋ ์์ ์ด์ฉํ์ฌ ํผ๋ฒ ํ
์ด๋ธ์ ๋ง๋ค๊ธฐ. df = pd.DataFrame({'๊ฐ์
์' : [1, 1, 1, 2, 2, 3], 'ํํด์' : [1, 2, 3, 2, 3, 3], 'ํํดํ์์' : [101, 52, 30, 120, 60, 130]}) df pivot_table() ํผ๋ฒํ
์ด๋ธ(pivot_table) ์์ฑ ์ ์ง์ ํ ์ธ์๋ค์ ์ข
๋ฅ values : ๊ฐ ๊ทธ๋ฃน ๋ณ๋ก ์กฐํํ ๊ฐ์ ๊ธฐ์กด ๋ฐ์ดํฐํ๋ ์์ ์ด ์ด๋ฆ index : ํ
์ด๋ธ์ ํ์ผ๋ก ๋ค์ด๊ฐ ๊ธฐ์กด ๋ฐ์ดํฐํ๋ ์์ ์ด ์ด๋ฆ columns : ํ
์ด๋ธ์ ์ด๋ก ๋ค์ด๊ฐ ๊ธฐ์กด..
2022. 7. 30.