상세 컨텐츠

본문 제목

시각화 총정리: pandas

멋사 AISCOOL 7기 Python/INPUT

by dundunee 2022. 10. 28. 00:27

본문

A. 판다스 API를 이용한 시각화 - 수치형 변수

1. 전체 수치변수에 대한 히스토그램

df.hist(bins=100, figsize=(12,8))
plt.show()

2. line

year_month = df["연도월"].value_counts().sort_index(ascending=True)
year_month.plot()

  • 선 추가
day_cnt = df["확진일"].value_counts().sort_index()
day_cnt.plot(title="일자별 확진수", figsize=(10, 3))
plt.axhline(1500, c="r", lw = 0.5, ls = "--") #1500에서, c: 색깔, lw: 선굵기, ls:선스타일

3. area

year_month.area()

4. bar

year_month.plot(kind="bar")

  • grid와 title 기능의 추가
year_month.plot(kind="bar", grid=True, title="연도월 확진자수")

  • rot와 title 기능 추가
weekday_count.plot(kind="bar", rot=0, title = "요일 별 확진 수", figsize = (10, 3))

B. 판다스 API를 이용한 시각화 - 범주형 변수

1. 한 개 변수에 대한 시각화

gu_count = df["거주구"].value_counts()
gu_count.plot(kind="bar", rot = 70)

2. 2개 변수에 대한 시각화

ym = pd.crosstab(index=df["연도"], columns=df["월"])
ym

barplor으로 시각화하기

ym.plot(kind="bar")
ym = pd.crosstab(index=df["연도"], columns=df["월"])
ym

barplot으로 시각화하기

ym.plot(kind="bar")

관련글 더보기