import numpy as np
import pandas as pd
# 데이터 불러오기
df=pd.read_csv("sc_cust_info_txn_v1.5.csv")
df.info()
df.head()
df.tail()
df.describe()
# "_" -> null 처리 후, 'age'칼럼 타입변경
cust=cust.replace("_", np.NaN)
cust=cust.astype({'age': float })
cust.info()
cust.head()
# null값 -> 15로 변경
cust=cust.fillna(15)
# null값 -> 다음행 값으로 변경
cust=cust.fillna(method='backfill')
# null값 -> 이전행 값으로 변경
cust=cust.fillna(method='ffill')
# 'age'칼럼 null값 -> 평균값으로 변경
cust['age']=cust['age'].replace(np.nan, cust['age'].mean())
# 'age'칼럼 null값 -> 중앙값으로 변경
cust['age']=cust['age'].replace(np.nan, cust['age'].median())
# 'age'칼럼 null값 -> 최빈값으로 변경
cust['age']=cust['age'].replace(np.nan, cust['age'].mode()[0])
# 'null값이 하나라도 있으면 해당 행 삭제
cust=cust.dropna()
cust.info()
# 모두가 null이면 해당 행 삭제
cust=cust.dropna(how='all')
cust.info()
# null이 아닌 값이 10개 미만인 행 삭제
cust=cust.dropna(thresh=10)
cust.info()
# 'class'칼럼이 null인 행 삭제
cust=cust.dropna(subset=['class'])
cust.info()
# 'column_a', 'column_b' 삭제
df.drop(['column_a', 'column_b'], axis=1, inplace=True)