python 판다스(pandas) DataFrame categorical 범주형 데이터 작업
DataFrame categorical 범주형 데이터 작업 원래 데이터 유형으로 다시 변환 s = Series(['a','b','a','c','b','d','a'], dtype='category') s = s.astype('string') 데이터 정렬 s = Series(list('abc'), dtype='category') print (s.cat.ordered) s=s.cat.reorder_categories(['b','c','a']) s = s.sort() s.cat.ordered = False 카테고리 이름 바꾸기 s = Series(list('abc'), dtype='category') s.cat.categories = [1, 2, 3] # in place s = s.cat.rename_categ..
2023. 11. 18.
python 판다스(pandas) DataFrame 결측치 확인 및 처리
DataFrame 결측치 처리/작업 시리즈 결측치 처리 s = Series( [8,None,float('nan'),np.nan]) s.isnull() #[False, True, True, True] s.notnull()#[True, False, False, False] s.fillna(0)#[8, 0, 0, 0] DataFrame 결측치 처리 df = df.dropna() # drop all rows with NaN df = df.dropna(axis=1) # same for cols df=df.dropna(how='all') #drop all NaN row df=df.dropna(thresh=2) # drop 2+ NaN in r # only drop row if NaN in a specified co..
2023. 11. 18.