본문 바로가기

세상 바라보는 시선 👁/Growth Hacking

[Pandas] Visualization 관련 정리 (시각화)


figure size 바꾸기

plt.figure(figsize = (가로, 세로)) 로 변경 가능하다.

plt.figure(figsize=(18,4))
dayofweek_order = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
sns.pointplot(data = train, x="datetime-hour", y = "count", hue ="datetime-dayofweek"
             , hue_order = dayofweek_order)

figure 여러개 보여주기 

nrows와 ncols 그리고 ax를 배치해서 만들 수 있다.

pandas seaborn으로 시각화를 하면 한 줄에 1개씩 이미지가 나오는데 여간 불편한게 아니다. 여러줄 나오게 변경하면 매우 간편한다.

# matplotlib로 실행하는 모든 시각화를 자동으로 쥬피터 노트북에 띄웁니다.
# %matplotlib inline
# mport seaborn as sns
# 데이터 시각화 패키지 matplotlib를 로딩합니다. 앞으로는 줄여서 plt라고 사용할 것입니다.
# import matplotlib.pyplot as plt

# 시각화 여러개 나오게 하기
figure, ((ax1,ax2,ax3), (ax4,ax5,ax6)) = plt.subplots(nrows = 2, ncols =3 )
figure.set_size_inches(18,12)

sns.barplot(data=train, x="datetime-year", y="count", ax= ax1)
sns.barplot(data=train, x="datetime-month", y="count", hue ="datetime-year", ax=ax2)
sns.barplot(data=train, x="datetime-day", y="count", hue ="datetime-year", ax=ax3)
sns.barplot(data=train, x="datetime-hour", y="count",hue ="datetime-year", ax=ax4)
sns.barplot(data=train, x="season", y="count",hue ="datetime-year", ax=ax5)
sns.barplot(data=train, x="datetime-hour", y="count",hue ="workingday", ax=ax6)

하나의 figure 크기 조절

# matplotlib를 활용해 그래프의 사이즈를 가로로 길게(18) 늘리고, 세로로 짧게(4) 줄입니다.
plt.figure(figsize = (18, 4))

# seaborn의 distplot으로 풍속(windspeed) 데이터를 시각화합니다.
# windspeed 데이터의 전체 분포(distribution)을 시각화합니다.
sns.distplot(train["windspeed"])

Value count, 각각 값이 몇개 있는지 확인

.value_counts()를 이용

Seaborn Plot 종류

Distplot : 데이터의 전체 분포(Distribution)을 시각화 한다.

Pointplot : 

Scatterplot

plt.figure(figsize = (8,8))
sns.scatterplot(data=train, x="temp", y="atemp", size = "count", 
                sizes=(0,120), hue = "windspeed") #sizes <- 복수형 주의

argument c 

c = y 로 입력하였다. 이때 y = array([ True, True, True, True, True, True, True, True, True, False], dtype=bool)였다. 더 다양한 색을 이용할 수도 있다.

참고하면 좋은 사이트

https://matplotlib.org/ - matplotlib 사이트

 

Matplotlib: Python plotting — Matplotlib 3.2.1 documentation

 

matplotlib.org

결측값 처리 관련 참고 사이트

 

[Pandas 6] 결측치(NaN), 중복 데이터 처리

판다스를 활용해서 결측치와 중복 데이터를 식별하고 처리하는 방법을 알아보자

yganalyst.github.io

 

♡를 눌러주시면 블로그를 작성하는데 큰 힘이 됩니다♪
로그인이 필요없어요.

이 블로그 인기글