반응형

Python 27

[Seaborn] EDA

EDA(Exploratory Data Analysis) : 주어진 데이터를 다양한 관점에서 탐색하며 인사이트를 도출 - row의 의미 - column의 분포 - 여러 column간 연관성 기본정보 데이터 불러오기 import pandas as pd import seaborn as sns %matplotlib inline df = pd.read_csv('./data/young_survey.csv') df.head() basic_info = df.iloc[:, 140:] # 마지막 7개 column basic_info.head() - 성별 / 우세 손 / 학벌 column 요소별 갯수 basic_info['Gender'].value_counts() basic_info['Handedness'].value_co..

Python/Seaborn 2024.01.09

[Seaborn] LM Plot, Cat Plot

LM (Linear Model) sns.lmplot(data=body_df, x='Height', y='Weight' ) ※ 만약 그래프가 안 뜬다면?? 해결 1) !pip install --upgrade --ignore-installed pip setuptools : 패키지 버전 수정 해결 2) 패키지 버전 수정 !pip install clyent==1.2.2 !pip install PyYAML==6.0.1 해결 3) pip 버전 수정 !pip install -U pip Cat Plot 데이터 가져오기 import pandas as pd import seaborn as sns laptops_df = pd.read_csv('./data/laptops.csv') laptops_df.head() - OS 종..

Python/Seaborn 2024.01.08

[Seaborn] KDE

Seaborn : Statistical Data Visualization 확률밀도함수 PDF (Probability Desity Function) : 데이터 셋의 분포를 나타냄 : 특정 구간에서의 확률을 나타냄 선의 확률은 0 키가 170일 확률 = 0 KDE(Kernel Density Estimation) : 우리가 갖고 있는 데이터는 굴곡이 많은 데이터임 : KDE를 사용해 굴곡 많은 데이터를 추측을 통해 진짜 분포에 가깝게 부드러운 곡선으로 바꿀 수 있음 키 몸무게 데이터 가져오기 body_df = pd.read_csv('./data/body.csv', index_col=0) body_df.head() 데이터 정렬 body_df['Height'].value_counts().sort_index() 그..

Python/Seaborn 2024.01.05

[Pandas] 데이터 클리닝

갖추어야 할 조건 : 완결성 / 유일성 / 통일성 / 정확성 완결성 (Completeness) : 필수정보가 누락됨이 없이 전부 존재해야 함 NaN 값이 있는 데이터 df = pd.read_csv('./data/attendance.csv', index_col=0) print(df, end='\n\n') 결측값 합계 isnull() print(df.isnull().sum(), end='\n\n') dropna(행) df.dropna(inplace=True) print(df, end='\n\n') dropna(column) df.dropna(axis='columns', inplace=True) print(df, end='\n\n') NaN을 0으로 대체 df.fillna(0, inplace=True) pri..

Python/Pandas 2024.01.05

[Pandas] DataFrame index/column

rename 함수 - position 컬럼을 Position으로 대문자 변경 - columns 사용 liverpool_df = pd.read_csv('./data/liverpool.csv', index_col=0) liverpool_df.rename(columns={'position' : 'Position'}) print(liverpool_df, end='\n\n') ∴ 바뀌지 않음 - rename 함수가 새로운 DataFrame을 만들어 컬럼을 변경 → 원래 DataFrame에는 영향이 없음 → inplace=True 적용 liverpool_df = pd.read_csv('./data/liverpool.csv', index_col=0) liverpool_df.rename(columns={'positio..

Python/Pandas 2024.01.02

[Pandas] DataFrame 값 쓰기 및 삭제

데이터 row 값 추가 iphone_df.loc['iPhone XR'] = ['2018-01-25', 6.1, '3GB', 'ios 12.0.1', 'Yes'] print(iphone_df, end='\n\n') 데이터 column 추가 iphone_df['제조사'] = 'Apple' print(iphone_df, end='\n\n') 데이터 row 삭제 iphone_df.drop('iPhone XS', axis='index', inplace=False) # row 삭제 print(iphone_df, end='\n\n') - inplace=True인 경우 - inplace=False인 경우 -- 원본 데이터 안바뀜 데이터 column 삭제 iphone_df.drop('제조사', axis='columns'..

Python/Pandas 2024.01.01

[Pandas] DataFrame 값 쓰기

특정 데이터 값(행, 열) 바꾸기 ##### DataFrame 값 쓰기 iphone_df.loc['iPhone 8', '메모리'] = '2.5GB' print(iphone_df, end='\n\n') 하나의 column의 모든 값 바꾸기 # 하나의 열 값 바꾸기 iphone_df.loc['iPhone 8'] = ['2016-09-22', '4.7', '2GB', 'iOS 11.0', 'No'] print(iphone_df) 리스트로 하나의 column의 값 전체를 바꿈 # 열 값 바꿈 (리스트) iphone_df['디스플레이'] = ['4.7in', '5.5in', '4.7in', '5.5in', '5.8in', '5.8in', '6.5in'] print(iphone_df, end='\n\n') 특정 값..

Python/Pandas 2023.12.31

[Pandas] DataFrame 인덱싱

loc 사용 import pandas as pd iphone_df = pd.read_csv('./data/iphone.csv', index_col=0) print(iphone_df.loc['iPhone 8', '메모리']) # [row, column] print(iphone_df.loc['iPhone 8', '가격']) # 존재하지 않는 column 이면 오류 Column 정보 접근 print(iphone_df.loc['iPhone X', :]) # 모든 column 정보 출력 print() print(iphone_df.loc['iPhone X']) # 모든 column 정보 출력 print(type(iphone_df.loc['iPhone X'])) # 시리즈 데이터 pandas 1차원 데이터 - typ..

Python/Pandas 2023.12.29
반응형