boostcampaitech4recsys1 / level1_bookratingprediction_recsys-level1-recsys-02

level1_bookratingprediction_recsys-level1-recsys-02 created by GitHub Classroom
5 stars 6 forks source link

data 전처리 관련 이슈 정리 #13

Closed Jeong-Junhwan closed 1 year ago

Jeong-Junhwan commented 1 year ago

user 관련

Jeong-Junhwan commented 1 year ago

코드 돌리니까 한시간 반 정도 걸리는데, 결과는 필요하면 csv로 보내드림. 한시간 반 걸릴 작업이 아닐 것 같은데 DataFrame 접근 방법이 잘못 되었는지 확인 해주시면 감사요..

# city가 같으면 state와 country가 같다는 점을 이용해 state와 country 뒤엎기
# 단, 다른 경우도 있을 수 있으므로 8% 이상 등장한 state나 country라면 바꾸지 않도록 변경했다. 
# =============================================
def fix_location(location: str, right_location: pd.Series) -> str:
    try:
        if right_location.loc[location]:
            return location
        else:
            return right_location.index[0]
    except:
        return right_location.index[0]

modify_city = users['location_city'].values

for city in tqdm(modify_city):
    try:
        right_state = users[(users['location'].str.contains(city))&(users['location_state'].notnull())]['location_state'].value_counts()
        right_country = users[(users['location'].str.contains(city))&(users['location_country'].notnull())]['location_country'].value_counts()

        right_state = right_state / right_state.sum() > 0.08
        right_country = right_country / right_country.sum() > 0.08

        users.loc[users['location_city']==city, 'location_state'] = users.loc[users['location_city']==city, 'location_state'].apply(fix_location, args=(right_state,))
        users.loc[users['location_city']==city, 'location_country'] = users.loc[users['location_city']==city, 'location_country'].apply(fix_location, args=(right_country,))

    except:
        pass
# =============================================
41ow1ives commented 1 year ago

modify_city = users['location_city'].unique() 이렇게하면 tqdm에서 20분으로 뜨긴 하는데 아직 결과 안 나와서 이게 되는지는 확신이 없네요..