Computer ๐ป/๋ฐ์ดํฐ ๋ถ์
[์ ๊ตญ ๋์ ๊ณต์ ํ์ค ๋ฐ์ดํฐ] ์๋๋ณ ๊ณต์ ๋ถํฌ
yeon42
2021. 8. 13. 00:49
728x90
4. ์๋๋ณ ๊ณต์ ๋ถํฌ
4.1 ์๋๋ณ ๊ณต์ ๋น์จ
- ์๋๋ณ๋ก ํฉ๊ณ ๋ฐ์ดํฐ ์ถ๋ ฅ
city_count = df["์๋"].value_counts().to_frame()
city_mean = df["์๋"].value_counts(normalize=True).to_frame()
- normalize=True : ๋น์จ๋ก ๊ตฌํ๊ธฐ
- ๋์ ํฉ์ณ์ฃผ๊ธฐ ์ํด dataframe ํํ๋ก ๋ฐ๊พธ์๋ค.
- ํฉ๊ณ์ ๋น์จ ํจ๊ป ๊ตฌํ๊ธฐ: merge
city = city_count.merge(city_mean, left_index=True, right_index=True)
city.columns = ["ํฉ๊ณ", "๋น์จ"]
city.style.background_gradient()
4.2 ๊ณต์๊ตฌ๋ถ๋ณ ๋ถํฌ
- "๊ณต์๊ตฌ๋ถ" ๋ณ๋ก ์์ ๋ค๋ฅด๊ฒ, "๊ณต์๋ฉด์ " ๋ณ๋ก ์์ ํฌ๊ธฐ ๋ค๋ฅด๊ฒ
plt.figure(figsize=(8, 9))
sns.scatterplot(data=df_park, x="๊ฒฝ๋", y="์๋", hue="๊ณต์๊ตฌ๋ถ", size="๊ณต์๋ฉด์ ", sizes=(10, 100))
4.3 ์๋๋ณ ๊ณต์๋ถํฌ
- "์๋" ๋ณ๋ก ์์ ๋ค๋ฅด๊ฒ, "๊ณต์๋ฉด์ " ๋ณ๋ก ์์ ํฌ๊ธฐ ๋ค๋ฅด๊ฒ
plt.figure(figsize=(8, 9))
sns.scatterplot(data=df_park, x="๊ฒฝ๋", y="์๋", hue="์๋", size="๊ณต์๋ฉด์ ", sizes=(10, 100))
- countplot ์ผ๋ก ์๋๋ณ ๋น๋์ ๊ทธ๋ฆฌ๊ธฐ
sns.countplot(data=df, y="์๋", order=city_count.index, palette="Greens_r")