[멋사 AI 7기] EDA1
EDA
태도
꾸준히 연습을 통해 안목을 기르는 게 중요하다. 한 가지 도구에 익숙해지면 새로운 도구에도 적응할 수 있음
수영, 자전거 타기와 같다
시각화 라이브러리(Pandas/Seaborn/Plotly)
Pandas
pandas는 필요한 정보를 미리 계산할 수 있는 장점을 활용할 수 있다.
이를 통해 시각화 속도 이슈를 줄일 수 있다.
Plotly
Plotly Express 사용권장
- high-level interface for data visualization
- seaborn 과 비슷한 사용법
- 사용법이 plotly.graph_objects 에 비해 비교적 간단한 편
points 옵션을 통해 strip plot 대체가능 * 다양한 옵션을 사용해 보자
Cufflinks
다양한 라이브러리를 참조해서 버전 호환성 문제가 있을 수 있다.
EDA
라이브러리 로드
- pandas
- numpy
- matplotlib.pyplot
시각화 폰트 설정
- koreanize_matplotlib
- %config InlineBackend.figure_format = ‘retina’
일부 데이터 보기
- head()
- tail()
- sample()
데이터 합치기
- pd.concat() * axis
중복 제거
- duplicated() : 중복 확인
- drop_duplicates() : 중복 제거 * df[df.duplicated()] 확인
인덱스 값 설정
- set_index()
정렬
- sort_index() * ascending
판다스 attributes
- shape
- dtypes
- columns
- index
데이터 요약
- info()
결측치 보기
- isnull() *sum(), mean()
기술통계
- describe() * include
- unique() : column에서 고유한 값을 가진 리스트, series에서만 사용 가능
- nunique() : column에서 고유한 값의 개수
오늘의 이모저모
Pandas Accessors
| Data Type | Accessor |
|---|---|
| Datetime, Timedelta, Period | dt |
| String | str |
| Categorical | cat |
| Sparse | sparse |
데이터 타입 변경
astype(“type”)
-
문자
astype(str) <= pandas series
str() <= python 문자열
-
날짜
pd.to_datetime()
Datetime properties
pd.date_range(start, end)
map / apply/ applymap
차이 복습
참고 사이트
USE CASE
- map
map is meant for mapping values from one domain to another, so is optimised for performance (e.g., df[‘A’].map({1:’a’, 2:’b’, 3:’c’}))
- apply
apply is for applying any function that cannot be vectorised (e.g., df[‘sentences’].apply(nltk.sent_tokenize))
- applymap
applymap is good for elementwise transformations across multiple rows/columns (e.g., df[[‘A’, ‘B’, ‘C’]].applymap(str.strip))

빈도수 구하기
한 개의 변수
- value_counts()
두 개의 변수
- crosstab
- pivot_table
- group by
기타
결측치 채우기
fillna(value)
to_frame()
컬럼 삭제
del df[“col”]
==판다스내부 벡터끼리의 연산, 비트와이즈 연산==
출처
- Plotly Expresshttps://plotly.com/python-api-reference/plotly.express.html
- Pandas Accessors
https://pandas.pydata.org/docs/reference/series.html#accessors
- Datetime properties
https://pandas.pydata.org/docs/reference/series.html#datetimelike-properties
- map / apply / applymap 차이 stackoverflow
https://stackoverflow.com/questions/19798153/difference-between-map-applymap-and-apply-methods-in-pandas
포스팅 공지
작성한 포스팅은 멋쟁이 사자처럼 AI SCHOOl의 수업 내용입니다.
댓글남기기