목록Programming/Python (20)
Allen's 데이터 맛집
pivot_table 함수란?Pandas의 pivot_table 함수는 데이터를 요약하고 집계하는 데 사용되는 강력한 도구입니다. Excel의 피벗 테이블과 유사한 기능을 제공하며, 데이터를 재구성하고 분석하는 데 매우 유용합니다.기본 사용법pivot_table의 기본 구조import pandas as pd# 예시 데이터data = { '날짜': ['2023-01-01', '2023-01-01', '2023-01-02', '2023-01-02'], '카테고리': ['A', 'B', 'A', 'B'], '매출': [100, 200, 150, 250]}df = pd.DataFrame(data)# 피벗 테이블 생성pivot = df.pivot_table(index='날짜', columns='카..
문제 상황Pandas의 merge 함수를 사용하여 여러 CSV 파일을 병합할 때 중복 열 이름으로 인해 다음과 같은 에러가 발생할 수 있습니다. MergeError : Passing 'suffixes' which cause duplicate columns {' ', ' ', '} is not allowed.라는 에러는 데이터 프레임을 병합할 때 동일한 열 이름이 발생하여 충돌이 일어나기 때문입니다. 이 문제를 해결하기 위해서는 각 병합 단계에서 동일한 열 이름에 대해 다른 접미사를 지정해야 합니다.기존코드import pandas as pd# 데이터 불러옴df1_oxid = pd.read_csv('Data/Oxid_000.csv')df1_soft = pd.read_csv('Data/Photo_Softbak..
Python으로 쥬피터 노트북으로 Matplotlib 그래프를 그릴 때 아래와 같은 문구와 함께 그래프 상에서 한글이 깨짐 현상을 가질 때가 있습니다. C:\ProgramData\anaconda3\Lib\site-packages\IPython\core\pylabtools.py:152: UserWarning: Glyph 45936 (\N{HANGUL SYLLABLE DE}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) C:\ProgramData\anaconda3\Lib\site-packages\IPython\core\pylabtools.py:152: UserWarning: Glyph 51060 (\N{HANGUL SYLLABLE ..
예외(exception) 란 코드를 실행하는 중에 발생한 에러를 뜻합니다. 예외가 발생했을 때도 스크립트 실행을 중단하지 않고 계속 실행하게 해 줘야 합니다. try에 실행할 코드를 넣고 except에 예외가 발생했을 때 처리하는 코드를 넣습니다. try ~ except try: print('나누기 전용 계산기') num1 = int(input('첫번째 숫자를 입력 : ')) num2 = int(input('두번째 숫자를 입력 :')) print('{0} / {1} = {2}'.format(num1,num2,int(num1/num2))) except ValueError : print('에러 발생!') 예외 발생 임의로 예외 처리를 설정 할 수 있다. raise 를 사용하여 설정 가능. try: print..