Notice
Recent Posts
Recent Comments
Tags
- tistory toc
- 티스토리 자동 목차
- tistory 목차
- NewYork Times 읽기
- matplotlib 객제 지향 방식
- jupyter notebook shell commands
- TOC
- magic command
- fig ax 사용
- 티스토리 목차
05-07 08:49
Archives
develop myself
pandas basic tips 본문
pandas.options.display
jupyter notebook의 output 설정을 확인하고 변경할 수 있다.
설정 가능한 display 목록 확인
import pandas as pd
# dir로 변경하고 싶은 설정 목록을 확인할 수 있음.
dir(pd.options.display)
현재 설정 값 확인
# 현재 설정을 확인하고 싶을 경우
pd.get_option('display.max_rows')
pd.get_option('display.max_columns')
설정 변경
pd.set_option('display.max_columns',None)
pd.set_option('display.max_rows',None)
# Pandas 숫자 출력 포맷팅
# https://financedata.github.io/posts/pandas-display-format.html
# 과학적 표기법(Scientific notation)을 사용하지 않는 경우
pd.set_option('display.float_format', '{:.2f}'.format)
# 과학적 표기법(Scientific notation)
pd.set_option('display.float_format', '{:.2e}'.format)
pd.set_option('display.float_format', '${:.2g}'.format) # 적당히 알아서
pd.set_option('display.float_format', None) # 원상복귀
비추천 방법
pd.options.display.max_columns = None
pd.options.display.max_rows = None
모듈의 object 리스트 확인
pandas에서 클래스 또는 메서드 이름이 잘 기억나지 않을 경우, 이런 방법으로 찾을 수 있다.
import pandas as pd
read_methods = [obj for obj in dir(pd) if obj.startswith('read')]
read_methods
파일 읽기/쓰기
help(pd.read_csv)
help(pd.DataFrame.to_csv)
데이터 확인
df.head()
df.tail()
df.shape
df.columns
df.dtypes
df.info()
df.describe()
df.describe(include='object')
문자열: 주요 메서드
pandas Series의 문자열을 다루는 메서드는 매우 많다.
여기서는 매우 극소수의 메서드만 소개.
# 문자열 데이터 탐색
df['col1'].str.contains('Lemon') # 포함 여부
df['col2'].str.match('Lemon') # 일치 여부
# replace : 문자열 변경
a = 'hello lemon'
a.replace('lemon', 'apple')
# strip : 앞뒤 공백 제거
b = ' corn '
b.strip()
dir(pd.Series.str)
'DataScience > Python' 카테고리의 다른 글
matplotlib cheatsheets, handout (0) | 2023.01.26 |
---|---|
matplotlib basic tips (0) | 2023.01.26 |
numpy basic tips (0) | 2023.01.26 |
Python help, dir (0) | 2023.01.26 |
jupyter notebook magic commands, shell commands (0) | 2023.01.26 |
Comments