240516 Today I Learn๐ก Seaborn ์๊ฐํ๋ฅผ ์ํ ํ์ด์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค ํ๋๋ก, matplotlib์ ๊ธฐ๋ฐ์ผ๋ก ํ๋ ๋ฐ์ดํฐ ์๊ฐํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค. ๋ฐ์ดํฐ ์ ํ์ ๋ฐ๋ฅธ Seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๊ตฌ๋ถ ๊ทธ๋ํ ์ ํํจ์์๋ฃ ์ ํํน์งLine Plotsns.lineplot์ฐ์ํ ๋ฐ์ดํฐ๋ฐ์ดํฐ์ ๋ณํ ๋ฐ ์ถ์ด๋ฅผ ์๊ฐํBar Plotsns.barplot๋ฒ์ฃผํ ๋ฐ์ดํฐ์นดํ
๊ณ ๋ฆฌ ๋ณ ๊ฐ์ ํฌ๊ธฐ๋ฅผ ์๊ฐ์ ์ผ๋ก ๋น๊ตHistogramsns.histplot์ฐ์ํ ๋ฐ์ดํฐ๋ฐ์ดํฐ ๋ถํฌ, ๋น๋, ํจํด ๋ฑ์ ์ดํดBox Plotsns.boxplot์ฐ์ํ ๋ฐ์ดํฐ์ ๋ถํฌ์ค์๊ฐ, ์ฌ๋ถ์์, ์ต์๊ฐ, ์ต๋๊ฐ, ์ด์์น ํ์ธScatter Plotsns.scatterplot๋ ๋ณ์ ๊ฐ ๊ด๊ณ๋ณ์ ๊ฐ์ ๊ด๊ณ, ๊ตฐ์ง, ์ด์์น ๋ฑ ํ์ธLine P..
๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ถ๋ฌ์ค๊ธฐimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as sns๋ฒ ์ด์ง ๋ฌธํญ1. ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐpandas๋ฅผ importํ ๋ค์ ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์์ ๋ฐ์ดํฐ๋ฅผ ํ์ธํ์ธ์.# ๋ฐ์ดํฐ ๋ถ๋ฌ์ค๊ธฐurl = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data'columns = ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width', 'Species']iris = pd.read_csv(url, header=None, names=columns) 2. ๋ฐ์ดํฐ ๊ตฌ์กฐ ํ์
ํ๊ธฐ๋ฐ์ดํฐ์
์ ์ฒซ 5ํ์ ์ถ๋ ฅํ๊ณ , ๋ฐ์ดํฐ..
240514 Today I LearnSeaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด ์ฐ์ ๋ ๊ทธ๋ฆฌ๊ธฐ๐ก Seaborn ์๊ฐํ๋ฅผ ์ํ ํ์ด์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค ํ๋๋ก, ๋ค์ํ ์ข
๋ฅ์ ๊ทธ๋ํ๋ฅผ ์์ฑํ๊ธฐ ์ํ ๋๊ตฌ๋ฅผ ์ ๊ณตํ๋ค.matplotlib ๊ธฐ๋ฐ๋น๊ต์ ์งง์ ์ฝ๋๋ก๋ ํต๊ณํ์ ์ฃผ์ ๊ทธ๋ํ๋ฅผ ๋น ๋ฅด๊ณ ํธ๋ฆฌํ๊ฒ ๋ง๋ค ์ ์์.Seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด ์ฐ์ ๋ ๊ทธ๋ฆฌ๊ธฐ1. seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ import ํด์ค๋ค.import seaborn as sns2. seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ฐ์ ๋๋ฅผ ๊ทธ๋ฆฌ๋ ํจ์๋ .scatterplot์ด๋ค.๐ก seaborn ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก scatter plot ๊ทธ๋ฆฌ๊ธฐsns.scatterplot(data=๋ฐ์ดํฐ ํ๋ ์, x=x์ถ์ ๋ค์ด๊ฐ ์ปฌ๋ผ, y=y์ถ์ ๋ค์ด๊ฐ ์ปฌ๋ผ)# ์ด๋ x์ y ๊ฐ์๋ df[..
240514 Today I Learn ๋ฐ์ดํฐ ๊ฒฐํฉํ๊ธฐConcat๐ก Concatํ๋ค์ค ๊ฐ์ฒด๋ค์ ์์ง/ ์ํ์ผ๋ก ๋ถ์ด๊ธฐpd.concat(['๋ฐ์ดํฐํ๋ ์1','๋ฐ์ดํฐํ๋ ์2'], axis=0/1)โMerge๐ก Mergepd.merge(๋ฐ์ดํฐํ๋ ์1, ๋ฐ์ดํฐํ๋ ์2, on="๊ณตํต๋ ์ปฌ๋ผ", join = 'inner/outer/left/right/cross')๊ณตํต๋ ์ปฌ๋ผ์ด ์๋ ๋ฐ์ดํฐํ๋ ์์ ํค๊ฐ์ ๊ธฐ์ค์ผ๋ก ํฉ์น๊ณ ์ ํ ๋ ์ฌ์ฉ ๊ฐ๋ฅํน์ ์ด์ ๋ฐ๋ผ SQL ์คํ์ผ์ ์กฐ์ธ์ ์ฌ์ฉํ ์ ์์ ๐ SQL์ ์กฐ์ธ๊ณผ pandas Merge ํจ์์ ์กฐ์ธ ์ต์
Comparison with SQL — pandas 2.2.2 documentationComparison with SQL Since many potential pa..
240514 Today I LearnData SelectionGetitem [ ]๐ก dataframe['์ปฌ๋ผ๋ช
']DataFrame์์๋ column์ ์ง์ ํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ ํํ ์ ์๋ค. ์ ํ๋ ๋ฐ์ดํฐ๋ series ํํ๋ก ๋ฐํ๋๋ค. ์์์ฌ๋ผ์ด์ฑ์ ์ด์ฉํด ์ถ์ถ ๊ฐ๋ฅ# ๊ฐ์ ๊ฒฐ๊ณผ๊ฐ์ ์ถ๋ ฅํ๋ ๋ ์ฝ๋df[0:3]df["20240513":"20240515"]์ซ์๋ก ์ฌ๋ผ์ด์ฑ ํ๋ ๊ฒฝ์ฐ [์์ํ ์ซ์ : ๋๋ ์ซ์ +1]๋ฌธ์๋ก ์ฌ๋ผ์ด์ฑ ํ๋ ๊ฒฝ์ฐ [์์ํ ๋ฌธ์ : ๋๋ ๋ฌธ์]Selection by label๐ก loc : ๋ผ๋ฒจ๋ช
์ผ๋ก ์์น๋ฅผ ์ง์ ํ์ฌ ๋ฐ์ดํฐ ์ถ์ถํน์ row๋ฅผ ๋งค์นญํด ์ถ์ถํ๋ ๊ฒฝ์ฐ# dates[0] = '2024-05-13'# row ๊ฐ์ด 2024-05-13์ธ ํ ์ถ์ถdf.loc[dates[0]]#..
240513 Today I LearnBasic data structures in pandasํ๋ค์ค์์ ์ ๊ณตํ๋ ๋๊ฐ์ง ๋ฐ์ดํฐ ํ์
Series : 1์ฐจ์ ํํ์ ๋ฐ์ดํฐ (ํ์ด์ฌ์ ๋๋ถ๋ถ์ ํ์
๋ค์ด ๋ค์ด๊ฐ ์ ์์)DataFrame : 2์ฐจ์ ํํ์ ํ๋ก ์ด๋ฃจ์ด์ง ๋ฐ์ดํฐ (ํ,์ด์ ๊ฐ๋
์ด ์กด์ฌํจ)๐ก ๋ฐ์ดํฐ์์ ์ด์ผ๊ธฐํ๋ ์ฐจ์์ด๋?๋ฐ์ดํฐ์ ์์ฑ(Attribute) ๊ฐ์์ ๋ฐ๋ผ ์ฐจ์์ ๊ตฌ๋ถํ๋ค.0์ฐจ์ : schalar(์ค์นผ๋ผ) → ๊ฐ1์ฐจ์ : vector(๋ฒกํฐ) → ๋ฆฌ์คํธ2์ฐจ์ : matrix(ํ๋ ฌ) → 2์ค ์ค์ฒฉ ๋ฆฌ์คํธ3์ฐจ์์ด์ : tensor(ํ
์) → 3์ค ์ด์ ์ค์ฒฉ ๋ฆฌ์คํธObject Creation1. Series ๋ง๋ค๊ธฐ : ๋ฆฌ์คํธ์ ๊ฐ์ ๋ฃ์ด์ ๋ง๋ค๊ธฐs = pd.Series([1,3,5,np.na..