๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

์ „์ฒด ๊ธ€36

[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/ํŒŒ์ด์ฌ] Matplotlib (1) - ๋ผ์ธ ํ”Œ๋กฏ(Line Plot), ํ”Œ๋กฏ ์ถ•(Plot axis), color bar legend, ๋‹ค์ค‘ ํ”Œ๋กฏ Matplotlib Matplotlib ํŠน์ง• ํŒŒ์ด์ฌ์˜ ๋Œ€ํ‘œ์ ์ธ ๊ณผํ•™ ๊ณ„์‚ฐ์šฉ ๊ทธ๋ž˜ํ”„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„  ๊ทธ๋ž˜ํ”„, ํžˆ์Šคํ† ๊ทธ๋žจ, ์‚ฐ์ ๋„ ๋“ฑ์˜ ๊ณ ํ’ˆ์งˆ ๊ทธ๋ž˜ํ”„ ์ œ๊ณต ์ €์ˆ˜์ค€ api๋ฅผ ์‚ฌ์šฉํ•œ ๋‹ค์–‘ํ•œ ์‹œ๊ฐํ™” ๊ธฐ๋Šฅ ์ œ๊ณต ๋‹ค์–‘ํ•œ ์šด์˜์ฒด์ œ์™€ ๊ทธ๋ž˜ํ”ฝ ๋ฐฑ์—”๋“œ์—์„œ ๋™์ž‘ ์‹ค์Šต ์ฝ”๋“œ ์ถœ์ฒ˜ : https://www.youtube.com/watch?v=5DfACSYgP0U import matplotlib as mpl from matplotlib import font_manager, rc import matplotlib.pyplot as plt import numpy as np import pandas as pd print(mpl.__version__) # seaborn ์Šคํƒ€์ผ ์‚ฌ์šฉ plt.style.use('seaborn-notebook').. 2022. 8. 3.
[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.