EDA : Exploratory Data Analysis, 탐색적 데이터 분석
데이터를 다양한 각도에서 관찰하고 이해하는 일련의 과정을 말한다.
데이터 분석 이전에 그래프나 통계적인 방법으로 자료를 직관적으로 바라보는 방법이다.
: 변수 하나에 대한 기술통계량(descriptive statistics)확인하기
: 변수 2개 간의 상관관계 분석
: 범주형 변수가 하나 이상 포함되어 있는 경우, 변수를 범주에 따라 분리한 뒤 위의 분석 방법에 따라 분석
: 모두 연속형 변수라면 연속형 변수를 Feature Engineering을 통해 범주형 변수로 변환한 후 분석 or 3차원 그래프를 그려 시각적으로 확인
: 데이터의 종류에 따라 적절한 그래프 선택
: 다양한 그래프 통해 피처들의 특성 파악하는 것이 중요

import warnings
#hide warnings
warnings.filterwarnings("ignore")
import klib
import pandas as pd
import seaborn as sns
df = sns.load_dataset("titanic")
df.head()
survived pclass sex age ... deck embark_town alive alone
0 0 3 male 22.0 ... NaN Southampton no False
1 1 1 female 38.0 ... C Cherbourg yes False
2 1 3 female 26.0 ... NaN Southampton yes True
3 1 1 female 35.0 ... C Southampton yes False
4 0 3 male 35.0 ... NaN Southampton no True
[5 rows x 15 columns]
결측치에 대한 프로파일링 플롯
klib.missing_plot(df)

#양의 상관관계 플롯
klib.corr_plot(df, split = 'pos')
#음의 상관관계 플롯
klib.corr_plot(df, split = 'neg')


klib.corr_plot(df, target = 'age')

klib.dist_plot(df)

결측치 제거
df_cleaning = klib.data_cleaning(df)
Shape of cleaned data: (784, 15) - Remaining NAs: 692
Dropped rows: 107
of which 107 duplicates. (Rows (first 150 shown): [47, 76, 77, 87, 95, 101, 121, 133, 173, 196, 198, 201, 213, 223, 241, 260, 274, 295, 300, 304, 313, 320, 324, 335, 343, 354, 355, 358, 359, 364, 368, 384, 409, 410, 413, 418, 420, 425, 428, 431, 454, 459, 464, 466, 470, 476, 481, 485, 488, 490, 494, 500, 511, 521, 522, 526, 531, 560, 563, 564, 568, 573, 588, 589, 598, 601, 612, 613, 614, 635, 636, 640, 641, 644, 646, 650, 656, 666, 674, 692, 696, 709, 732, 733, 734, 738, 739, 757, 758, 760, 773, 790, 792, 800, 808, 832, 837, 838, 844, 846, 859, 863, 870, 877, 878, 884, 886])
Dropped columns: 0
of which 0 single valued. Columns: []
Dropped missing values: 177
Reduced memory by at least: 0.06 MB (-75.0%)
$ pip install -U ydata-profiling
import numpy as np
import pandas as pd
from ydata_profiling import ProfileReport
df = pd.DataFrame(np.random.rand(300, 5), columns = ['a', 'b', 'c', 'd', 'e'])
print(df.head())
a b c d e
0 0.256913 0.029879 0.703868 0.460997 0.229289
1 0.123758 0.289923 0.876893 0.730410 0.087231
2 0.898840 0.796030 0.097658 0.032270 0.882305
3 0.810458 0.693949 0.651186 0.555393 0.085024
4 0.869552 0.245806 0.887612 0.964292 0.535038
import numpy as np
import pandas as pd
from ydata_profiling import ProfileReport
df = pd.DataFrame(np.random.rand(100, 5), columns=["a", "b", "c", "d", "e"])
print(df.head())
a b c d e
0 0.475418 0.632401 0.833304 0.488212 0.457984
1 0.926178 0.982091 0.965655 0.221599 0.208072
2 0.148913 0.149262 0.494310 0.485184 0.313386
3 0.648525 0.330472 0.271104 0.339321 0.677158
4 0.565470 0.245023 0.396740 0.301198 0.384929
profile = ProfileReport(df, title = "Ydata Profiling Report")
print(profile)
#profile.to_notebook_iframe()
profile.to_file("..문서/my_profiling_report.html")

import numpy as np
import pandas as pd
from ydata_profiling import ProfileReport
import seaborn as sns
#seaborn Titanic 데이터셋 import
df_titanic = sns.load_dataset("titanic")
print(df_titanic.head())
survived pclass sex age sibsp parch ... who adult_male deck embark_town alive alone
0 0 3 male 22.0 1 0 ... man True NaN Southampton no False
1 1 1 female 38.0 1 0 ... woman False C Cherbourg yes False
2 1 3 female 26.0 0 0 ... woman False NaN Southampton yes True
3 1 1 female 35.0 1 0 ... woman False C Southampton yes False
4 0 3 male 35.0 0 0 ... man True NaN Southampton no True
[5 rows x 15 columns]
profile.to_file("..source/titanic_profiling_report.html")

github konlp rawdata link 에서 ko_test.csv파일 다운로드
import pandas as pd
import numpy as np
from ydata_profiling import ProfileReport
movie_df = pd.read_csv("C:/Users/USER_0/Downloads/ko_test.csv", sep=",")
print(movie_df.head(5))
id document
0 8544678 뭐야 이 평점들은.... 나쁘진 않지만 10점 짜리는 더더욱 아니잖아
1 6825595 지루하지는 않은데 완전 막장임... 돈주고 보기에는....
2 6723715 3D만 아니었어도 별 다섯 개 줬을텐데.. 왜 3D로 나와서 제 심기를 불편하게 하죠??
3 6315043 진정한 쓰레기
4 8932678 갈수록 개판되가는 중국영화 유치하고 내용없음 폼잡다 끝남 말도안되는 무기에 유치한c...
pf_movie = ProfileReport(movie_df, title = "네이버 영화 리뷰 데이터 프로파일링 보고서")
pf_movie.to_html()

-pygwalker 설치
pip install pygwalker
윈도우 환경에서 설치, 터미널창에 입력
import pandas as pd
import pygwalker as pyg
import seaborn as sns
df_titanic = sns.load_dataset("titanic")
gwalker = pyg.walk(df_titanic).display_on_jupyter()