[멋사 AI 7기] EDA 이모저모
EDA
파일시스템의 대소문자 구분
대/소문자 구분 조정
“Windows 및 Linux 대/소문자 구분 간의 차이점”
Linux 및 Windows 파일 및 디렉터리 둘 다로 작업할 때 대/소문자 구분 처리 방법을 조정해야 할 수 있다.
표준 동작:
Windows 파일 시스템은 파일 및 디렉터리 이름을 대/소문자를 구분하지 않는 것으로 처리 ex) FOO.txt 및 foo.txt 동일한 파일로 처리
Linux 파일 시스템은 파일 및 디렉터리 이름을 대/소문자를 구분하는 것으로 처리 ex) FOO.txt 및 foo.txt 고유 파일로 처리
Random Generator
numpy.random.seed() vs numpy.random.default_rng() - 사용 권장
Stop Using NumPy’s Global Random Seed
global random state vs own random state
default_rng의 이점
함수와 클래스 사이에 난수 생성기를 전달할 수 있다.
즉, 각 개인 또는 함수는 전역 시드를 재설정하지 않고도 고유한 random state 를 가질 수 있다.
또한 각 스크립트는 재현 가능 함수에 난수 생성기를 전달할 수 있다.
=> 프로젝트의 각 부분에서 어떤 난수 생성기가 사용되는지 정확히 알 수 있다.
Pandas
- to_datetime(arg, format)
- dt accessor
-
options and setting
pd.options.display.max_columns = None
merge
df1.merge(df2, on=”key”)
- how : {‘left’, ‘right’, ‘outer’, ‘inner’, ‘cross’}, default ‘inner’
- on : label or list
Column or index level names to join on.
These must be found in both DataFrames.
If on is None and not merging on indexes then this defaults to the intersection of the columns in both DataFrames.
groupby 메서드 체이닝
groupby 메서드로 생성된 결과물은 DataFrameGroupBy object로 DataFrame과 다르다.
DataFrameGroupBy object에는 여러 메서드를 적용할 수 있다.
메서드 체이닝: 여러 메서드를 붙여 사용하는 것
map function
map lambda 안 써줘도 되는 경우 - dict
gender_dict = {1 : “남자”, 2 : “여자”}
df[“성별”] = df[“성별코드”].map(gender_dict) / map(lambda x : gender_dict(x))
map 대신 replace 사용가능
map과 replace의 차이
map은 기존의 값들을 맵핑하여 변환하기 때문에, 딕셔너리에 값이 존재하지 않으면 맵핑할 수 없어 NaN을 반환
replace는 값을 바꿔주는 용도이기 때문에, 값이 존재하지 않아도 기존 값을 그대로 유지
시각화
heatmap 상관계수
- numpy 이용 mask 만들기
np.ones(shape) == np.ones_like(array_like)
np.triu[tril]
- seaborn heatmap
sns.heatmap(corr, annot=True, fmt=”.2f”, cmap=”coolwarm”, vmin=-1, vmax=1, mask=mask)
vmin/vmax 지정해주지 않으면 데이터 및 기타 키워드 인수에서 추론 - 데이터의 최소/최대
출처
- 대/소문자 구분 조정https://learn.microsoft.com/ko-kr/windows/wsl/case-sensitivity
- Random Generator
https://numpy.org/doc/stable/reference/random/generator.html
- Stop Using NumPy’s Global Random Seed
https://builtin.com/data-science/numpy-random-seed
- pandas.to_datetime
https://pandas.pydata.org/docs/reference/api/pandas.to_datetime.html
- Datetime properties
https://pandas.pydata.org/docs/reference/series.html#api-series-dt
- Options and settings
https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html
- pandas.DataFrame.merge
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html
- map과 replace의 차이 https://abluesnake.tistory.com/142
포스팅 공지
작성한 포스팅은 멋쟁이 사자처럼 AI SCHOOl의 수업 내용입니다.
댓글남기기