반응형
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_categories([4,5,6])
s.cat.categories = ['Group ' + str(i)
for i in s.cat.categories]
새 카테고리 추가
s = s.cat.add_categories([4])
카테고리 삭제
s = s.cat.remove_categories([4])
s.cat.remove_unused_categories() #inplace
참고 : https://www.geeksforgeeks.org/pandas-cheat-sheet
Pandas Cheat Sheet for Data Science in Python
This cheat sheet provides a quick reference to the most common Pandas commands, covering everything from data loading and manipulation to plotting and visualization. Whether you're a beginner or a seasoned data scientist, this cheat sheet is a valuable res
www.geeksforgeeks.org
반응형
'Python' 카테고리의 다른 글
VCF 파일 pandas dataframe 으로 전환하기 (0) | 2024.03.15 |
---|---|
python 판다스(pandas) DataFrame 기초통계 확인하기 (24) | 2023.11.18 |
python 판다스(pandas) DataFrame 결측치 확인 및 처리 (6) | 2023.11.18 |
python 판다스(pandas) DataFrame matplotlib plotting 그래프 만들기 (2) | 2023.11.16 |
python 판다스(pandas) 소개 및 기능 (0) | 2023.11.12 |