빅데이터 분석기사/데이터마님 4

Q67 ~ 79 dt 시계열 전처리 잔뜩

q67Yr_Mo_Dy에 년도가 2061년 이상의 경우에는 모두 잘못된 데이터이다. 해당경우의 값은 100을 빼서 새롭게 날짜를 Yr_Mo_Dy 컬럼에 정의하라def fix_century(x): import datetime year = x.year - 100 if x.year >= 2061 else x.year return pd.to_datetime(datetime.date(hyear, x.month, x.day))df['Yr_Mo_Dy'] = df['Yr_Mo_Dy'].apply(fix_century)q68df.groupby('Yr_Mo_Dy'.dt.year).mean()q69 dt.weekday df['weekday'] = df['Yr_Mo_Dy'].dt.weekdayq70조건 하나 ..

Q ~ 66 groupby, lambda, map

value_counts()각 칼럼의 갯수 구함normalize=True 빈도 구하는 파라미터 # q45 데이터의 각 host_name의 빈도수를 구하고, host_name 정렬해 상위 5개 출력하라# df.value_counts('host_name', normalize=True).head()df.host_name.value_counts().sort_index().head()host_name'Cil 1(Ari) HENRY LEE 1(Email hidden by Airbnb) 6(Mary) Haiy 1-TheQueensCornerLot 1Name: count, dtype: int64size() 메소..

데이터 전처리 100문제 Q20~43 - duplicate(), str, isin()

filteringdf.loc[df['quantity']==3].head()reset_index(drop=True)# q22 reset_index() 안에 drop True 안 쓰면 index 칼럼이 새로 생김 꼭 추가하기ans = df.loc[df['quantity']==3].reset_index(drop=True).head()print(ans)and -> & !!!df['new_price'] = df.new_price # q27 조건 and -> & 틀림# ()로 묶기# 복잡할 때는 df.new_price 가능# df.loc[(df['new_price'] sort_values('new_price', ascending=False)파라미터 ascending# sort_values 내림차순 파라미터는 asc..

데이터 전처리 100문제 Q1~19 - selecte_dtypes(), quantile()

# 11q - 틀림# select_dtypes()# selected_dtypes 아님!!# 메소드 안에서 exclude, include로 조건 설정 가능 ans = df.select_dtypes(exclude=object).columnsans# Q17평균 속도 컬럼의 4분위 범위 값을 구하라# quantile 함수 활용하기# 잘못된... 답 ㅋㅋㅋ# q3 = df['평균 속도']* 0.75%# q1 = df['평균 속도']* 0.25%# IQR = q3 - q1# print(IQR)df['평균 속도'].quantile(0.75) - df['평균 속도'].quantile(0.25)