import pandas as pd
import numpy as np
import seaborn as sns
# 0.11.0 버전에서 변화가 많으니 이 버전 이상을 사용해 주세요.
!pip install seaborn --upgrade
# 0.11.2
#seaborn에 내장되어 있는 데이터 셋을 가져옴
df = sns.load_dataset("mpg")
Pandas Profiling
!pip install pandas-profiling==3.1.0
from pandas_profiling import ProfileReport
profile = ProfileReport(df, title="Pandas Profiling Report MPG")
# 주피터 노트북이 있는 위치에 html파일이 생성됩니다.
profile.to_file("pandas_profile_report.html")
Sweetviz
!pip install sweetviz
import sweetviz as sv
my_report = sv.analyze(df)
my_report.show_html()
Autoviz(car var plot, distplots, violinplots, heatmaps, pairscatter): bokeh로 시각화해주는 추상화된도구
!pip install autoviz
from autoviz.AutoViz_Class import AutoViz_Class
AV = AutoViz_Class()
filename = "<https://raw.githubusercontent.com/mwaskom/seaborn-data/master/mpg.csv>"
sep = ","
dft = AV.AutoViz(
filename,
sep=",",
depVar="",
dfte=None,
header=0,
verbose=0,
lowess=False,
chart_format="html",
# chart_format="bokeh",
max_rows_analyzed=150000,
max_cols_analyzed=30,
# save_plot_dir=None
)
df.info()
df.isnull().sum()
df.isnull().mean()
plt.figure(figsize = (12, 8))
sns.heatmap(df.isnull(), cmap = "gray")
print(plt.colormaps())
df.describe()
#범주형데이터에 대한 기술통계값
df.describe(include = "object")
# 범주형데이터이나 수치형데이터로 인식되어서 기술통계값이 추출 된 경우
# 데이터 타입을 변경하고 기술통계값 추출
df[["cylinders", "model_year"]].astype(str).describe()
df.nunique() # 컬럼별 유일값 추출
# 수치형 변수 mpg의 unique 값 보기
df["mpg"].unique()
df.hist(figsize=(12, 8), bins = 40)
plt.show()
# skew를 통해 전체 수치변수에 대한 왜도 구하기
df.skew()
df.skew().sort_values() #정렬
# kurt를 통해 전체 수치변수에 대한 첨도 구하기
df.kurt()
df.kurt().sort_values(ascending=False)
df["mpg"].describe()
df["mpg"].agg(["skew", "kurt", "mean", "median"])
sns.displot(data = df, kde = True)
sns.displot(data = df, x = "mpg", kde = True)
sns.displot(data = df, x = "mpg", kde = True, hue = "origin", col = "origin")
sns.kdeplot(data = df, x = "mpg")
sns.rugplot(data = df, x = "mpg")
sns.boxplot(data = df, x = "mpg")
sns.violinplot(data = df, x = "mpg")
#스케일링: 표준화
df_num = df.select_dtypes(include = "number")
df_std = (df_num - df_num.mean()) / df_num.std()
df_std.describe().round(2)
sns.violinplot(data = df_std)
sns.scatterplot(data = df, x = "mpg", y = "horsepower")
sns.regplot(data = df, x = "mpg", y = "horsepower")
sns.residplot(data = df, x = "mpg", y = "horsepower")
regplot과 residplot의 차이?
sns.lmplot(data = df, x = "mpg", y = "horsepower", hue = "origin")
#col은 서브플롯을 그릴 수 있음
sns.lmplot(data = df, x = "mpg", y = "horsepower", hue = "origin", col = "origin")
sns.jointplot(data = df, x = "mpg", y = "horsepower", kind = "hex")
sns.pairplot(data = df.sample(100))
# origin 값에 따라 다른 색상으로 그리기
sns.pairplot(data = df.sample(100), hue = "origin" )
sns.lineplot(data = df, x = "model_year", y = "mpg")
sns.relplot(data = df,x = "model_year", y = "mpg", hue = "origin", col = "origin" )
# relplot 의 kind 옵션을 통해 선그래프를 그립니다.
sns.relplot(data = df,x = "model_year", y = "mpg", hue = "origin", col = "origin" , kind = 'line', ci = None)
df.corr()
# heatmap 을 통해 상관계수를 시각화 합니다.
sns.heatmap(corr, cmap = "coolwarm")
sns.heatmap(corr, cmap = "coolwarm", annot=True) #annot은 숫자 나타남의 유무
mask = np.triu(np.ones_like(corr))
#mask로 상삼각에서 1로 표시된 행열들을 모두 지움
sns.heatmap(corr, cmap = "coolwarm", annot=True, mask = mask)
[크롤링] FinanceDataReader, 네이버금융 뉴스기사 크롤링 (0) | 2022.09.28 |
---|---|
[EDA] 범주형데이터 기술통계 및 시각화 (0) | 2022.09.28 |
1주차 과제 뒷풀이: 인덱싱은 리스트나 문자열만! (0) | 2022.09.22 |
앤스컴 콰르텟 (0) | 2022.09.22 |
[시각화] Seaborn (0) | 2022.09.22 |