Python
-
관계 그래프 그리기Python 2018. 11. 16. 11:35
import numpy as npimport pandas as pd import seaborn as sns import matplotlib.pyplot as plt %matplotlib inline # seaborn 라이브러리에내장된 데이터 불러오기 tips = sns.load_dataset("tips") # 관계 그래프 그리기 # 산점행렬도의 upper triangular matrix에 산점도와 회귀직선 # 산점행렬도의 lower triangular matrix에 이차원 밀집도 # 산점행렬도의 diagonal matrix에 히스토그램 pair_grid = sns.PairGrid(tips) pair_grid = pair_grid.map_upper(sns.regplot) pair_grid = pair_gr..
-
이차원 밀집도 그리기Python 2018. 11. 16. 11:07
import numpy as npimport pandas as pd import seaborn as sns import matplotlib.pyplot as plt %matplotlib inline # seaborn 라이브러리에내장된 데이터 불러오기 tips = sns.load_dataset("tips") # 이차원 밀집도 그리기 : 음영 효과를 넣음 ax = plt.subplot() ax = sns.kdeplot(data = tips.total_bill, data2 = tips.tip, shade = True)ax.set_title("Kernel Density Plot of Total Bill and Tip") ax.set_xlabel("Total Bill") ax.set_ylabel("Tip") # ..
-
데이터 시각화가 필요한 이유 : Ansombe's QuarterPython 2018. 11. 15. 16:12
import matplotlib.pyplot as pltimport numpy as np import pandas as pd import seaborn as sns %matplotlib inline # 데이터 불러오기 anscombe = sns.load_dataset("anscombe") # 데이터 분할하기 d1 = anscombe.loc[anscombe.dataset == "I", ] d2 = anscombe.loc[anscombe.dataset == "II", ] d3 = anscombe.loc[anscombe.dataset == "III", ] d4 = anscombe.loc[anscombe.dataset == "IV", ] # 그래프의 기본 틀 만들기fig = plt.figure() # 그래프의 ..
-
Missing Value 처리Python 2018. 11. 1. 23:22
import pandas as pd # 데이터 읽어오기 test = pd.read_excel("d:/test.xlsx") test # missing value 확인 test.isna() # age에 있는 missing value를 0으로 대체하기 test.age = test.age.fillna(0) test # age에 있는 missing value를 age의 평균으로 대체하기 test.age = test.age.fillna(test.age.mean()). test # 행 중에서 하나라도 missing value가 있으면 해당 행을 삭제하기 test.dropna() # 행의 모든 값이 missing value인 경우 해당 행을 삭제하기 test.dropna(how = "all)