pandas: read_excel
pd.read_excel(io, sheet_name=0, header=0, index_col=None)#df = pd.read_excel('등록인구_20250721135412.xlsx', header = 1) #1열을 컬럼명으로 만들어라#read_excel - header: 컬럼이름으로 사용할 영역 - index_col : 인덱스로 사용할 컬럼 지정 - usecols : 사용할 컬럼 지정#io는 우리가 입력한 경로 값#0으로 지정한 것은 위치 값, 두번째시트 불러오고싶으면 sheet_name = 1, 문자열 입력시 해당시트 불러오며, [0,1,"Sheet5"]처럼 여러개 선택하면 선택한 시트를 딕셔너리로 통합해 가져옴, None하면 모든 시트를 딕셔너리를 통합해 가져옴 #header=0도 위치 값이며,..
2025. 7. 15.
Plotly 기초 / 스타일 설정하기
#주요 시각화 라이브러리#matplotlib: standard, seaborn: advanced version of matplotlib, plotly: new and interactive viz libimport plotly.express as pxfig = px.그래프종류(data_frame=데이터, x=X축 컬럼, y=Y축 컬럼, color=범례 컬럼, title=제목, labels=dict(X축 컬럼=X축 라벨, Y축 컬럼=Y축 라벨), width=그래프 가로길이, height=그래프 세로길이, text_auto=True/False)fig.show()#그래프종류: line, bar, box...#examplefig = px.bar(df_groupby, x='species', y='body_mass_..
2025. 7. 14.
pandas: stack, unstack, melt (데이터 구조 변경)
#stack : 컬럼 레벨에서 인덱스 레벨로 데이터프레임을 변경합니다.#unstack : 인덱스 레벨에서 컬럼 레벨로 데이터프레임을 변경합니다.pivot = pd.pivot_table(df, index=['Sex','Pclass'], values=['Survived','Fare'], aggfunc=['mean','median','sum'])pivot .stack(숫자, future_stack=True) #숫자만 쓰는것은 나중에 없어질 예정이라, future_stack=True를 꼭 같이 써주자.pivot.stack(0, future_stack=True) #컬럼의 첫번째 레벨을 인덱스로 내립니다.#0대신 1쓰면 두번째 레벨을 인덱스로 내림.unstack(숫자)pivot.unstack(1) #인덱스의 두번째..
2025. 7. 14.