반응형
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 col
df = df.dropna(df['col'].notnull())
결측치 기록
df.fillna(0, inplace=True) # np.nan -> 0
s = df['col'].fillna(0) # np.nan -> 0
df = df.replace(r'\s+', np.nan,
regex=True) # white space -> np.nan
참고 : https://www.geeksforgeeks.org/pandas-cheat-sheet
Pandas Cheat Sheet for Data Science in Python
This cheat sheet provides a quick reference to the most common Pandas commands, covering everything from data loading and manipulation to plotting and visualization. Whether you're a beginner or a seasoned data scientist, this cheat sheet is a valuable res
www.geeksforgeeks.org
반응형
'Python' 카테고리의 다른 글
python 판다스(pandas) DataFrame 기초통계 확인하기 (24) | 2023.11.18 |
---|---|
python 판다스(pandas) DataFrame categorical 범주형 데이터 작업 (10) | 2023.11.18 |
python 판다스(pandas) DataFrame matplotlib plotting 그래프 만들기 (2) | 2023.11.16 |
python 판다스(pandas) 소개 및 기능 (0) | 2023.11.12 |
python 판다스(pandas) DataFrame 합치기 merge joining groupby 작업 (0) | 2023.11.12 |