본문 바로가기

Python53

python 판다스(pandas) DataFrame 기초통계 확인하기 DataFrame 기초통계 요약 통계 s = df['col1'].describe() df1 = df.describe() 주요 통계 메소드 df.corr() # pairwise correlation cols df.cov() # pairwise covariance cols df.kurt() # kurtosis over cols (def) df.mad() # mean absolute deviation df.sem() # standard error of mean df.var() # variance over cols (def) 값 개수(count) s = df['col1'].value_counts() 교차표(빈도수) ct = pd.crosstab(index=df['a'], cols=df['b']) 분위수 및 순위.. 2023. 11. 18.
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.
python 판다스(pandas) DataFrame matplotlib plotting 그래프 만들기 DataFrame Plotting matplotlib 불러오기, matplotlib 스타일 선택 import matplotlib.pyplot as plt print(plt.style.available) plt.style.use('ggplot') 참고 : https://matplotlib.org/stable/plot_types/index.html Plot types — Matplotlib 3.8.1 documentation Plot types Overview of many common plotting commands provided by Matplotlib. See the gallery for more examples and the tutorials page for longer examples. Pairw.. 2023. 11. 16.
반응형