728x90
이전 내용은 아래 글에서 확인 하실 수 있습니다.
[Data Analysis/Kaggle] - [Kaggle] Zomato Bangalore Restaurants 데이터 분석 (데이터 확인 / 질문하기)
[Kaggle] Zomato Bangalore Restaurants 데이터 분석 (데이터 확인 / 질문하기)
Zomato Bangalore Restaurants 데이터 분석 데이터 출처 : https://www.kaggle.com/himanshupoddar/zomato-bangalore-restaurants Zomato Bangalore Restaurants Restaurants of Bengaluru www.kaggle.com 1..
sks8410.tistory.com
3. 데이터 전처리
3-1 불필요한 컬럼 삭제
# url, phone, menu_item 컬럼은 사용하지 않을 것이므로 삭제
zomato = zomato.drop(["url", "phone", "menu_item"], axis = 1)
print(zomato.shape)
zomato.head()
3-2 중복 데이터 확인
zomato.duplicated().sum()
중복 데이터가 50개가 존재하여 삭제하도록 하겠습니다.
# 중복 데이터 삭제
zomato = zomato.drop_duplicates()
print(zomato.shape)
zomato.head()
3-3 결측치 처리
# Nan 값이 존재하는 행 전부 삭제
zomato = zomato.dropna(how = "any")
print(zomato.shape)
zomato.isnull().sum()
3-4 컬럼명 변경
zomato = zomato.rename(columns = {"approx_cost(for two people)" : "cost",
"listed_in(type)" : "list_type",
"listed_in(city)" : "list_city"})
zomato.columns
3-5 컬럼 타입 변경
# cost 컬럼의 콤마(,) 삭제 후 숫자 타입으로 변경
zomato["cost"] = zomato["cost"].replace(",", "", regex = True) # 콤마(,) 삭제
zomato["cost"] = pd.to_numeric(zomato["cost"]) # 숫자 타입으로 변경
zomato.info()
# rate 컬럼 /5 삭제 후 rating 컬럼에 지정
zomato["rating"] = zomato["rate"].replace("/5", "", regex = True)
zomato["rating"].unique()
# rating 컬럼의 NEW 를 0으로 변경 후 숫자 타입으로 변경
zomato["rating"] = zomato["rating"].replace("NEW", "", regex = True)
zomato["rating"] = pd.to_numeric(zomato["rating"])
print(zomato.shape)
print(zomato["rating"].unique())
zomato.head()
3-6 online_order, book_table 컬럼
# Yes -> 1, No -> 0 으로 변경
zomato["online_order"] = zomato["online_order"].map({"Yes" : 1, "No" : 0}).astype(int)
zomato["book_table"] = zomato["book_table"].map({"Yes" : 1, "No" : 0}).astype(int)
print(zomato.shape)
zomato.head()
728x90
'Data Analysis > Kaggle' 카테고리의 다른 글
[Kaggle] Nexfilx movies and TV shows 데이터 분석 1 (데이터 확인 / 질문) (0) | 2021.10.29 |
---|---|
[Kaggle] Zomato Bangalore Restaurants 데이터 분석 3 (EDA / 시각화 / 리뷰) (0) | 2021.10.29 |
[Kaggle] Zomato Bangalore Restaurants 데이터 분석 1 (데이터 확인 / 질문하기) (0) | 2021.10.26 |
[Kaggle] Personal Loan 데이터 분석 3 (EDA / 시각화 / 리뷰) (0) | 2021.10.13 |
[Kaggle] Personal Loan 데이터 분석 2 (데이터 전처리) (0) | 2021.10.13 |