SQL 실습(HR) EDA+Visualization

Jenny·2024년 6월 14일

EDA: Exploratory Data Analysis (탐색적 데이터 분석)

  1. Data 훑어보기

    • Info, describe
    • Null check
    • Duplicates check
    • Type check
  2. Data 재구조화

    • groupby
    • pivot_table
    • stack/unstack
  3. Col Relation 파악

    • Heatmap correlation
    • Bar / Regplot / Histplot
    • FacetGrid
    • Jointplot
    • 반복문으로 subplots

# 특정 타입 선택하기
df.select_dtypes(include='int64')

# heatmap
sns.heatmap (df[top8cols].corr(), annot=True, cmap='Blues')

# bar graph - simple
plt.title('Title')
plt.bar (df['colx'], df['coly']
plt.xlabel ('xname')
plt.ylabel ('yname')
plt.show()

# bar graph - facetgrid
facet = sns.FacetGrid (df, col='col', row='row', height=5)
facet.map_dataframe (sns.barplot, x='xcol', y='ycol')
facet = facet.fig.subplots_adjust (wspace=.2, hspace=.2)


# Regplot - 1
sns.regplot (df, x='xcol', y='ycol')

# Regplot - 2
facet = sns.FacetGrid (df, col='col', row='row', hue='h', hue_order=['1', '2'], palette={'1': 'red', '2': 'grey'})
facet.map_dataframe (sns.regplot, x='xcol', y='ycol', fit_reg=False)
facet.add_legend()


# Histplot
sns.histplot (df['col'])

# enumerate()
cols = ['col1', 'col2', 'col3']
for i, col in enumerate (cols):
	axes = plt.subplot (6, 3, i+1) #nrows, ncols, index
	sns.histplot (x=df[col], hue=df['Gender'])
plt.tight_layout()
plt.show()


# Jointplot
sns.jointplot (df, x='xcol', y='ycol', kind='reg', hue='Gender')

# marker: '.'Dot, 'o'Circle, '+'Plus, '^'Triangle, 's'Square, '*'Star, 'D'Diamond
# kind: kde, reg, scatter
# marginal_ticks=True: marginal data (histogram)에 축 추가
# marginal_kws: bins-> histogram 두께?
j = sns.jointplot (df, x='xcol', y='ycol'
               , marker='+' 
               , marginal_ticks=True
               , marginal_kws=dict(bins=30, rug=True))
j.plot_joint (sns.kdeplot, color='r') # 등고선
j.plot_marginals (sns.rugplot, color='r', height=-.15, clip_on=False) # 러그

이 글은 제로베이스 데이터 분석 취업 스쿨의 강의자료 일부를 발췌하여 작성되었습니다.

profile
I like to movie movie

0개의 댓글