320x100
데이터 개요
Bank Marketing Data Set : https://archive.ics.uci.edu/ml/datasets/bank+marketing
UCI Machine Learning Repository: Bank Marketing Data Set
Bank Marketing Data Set Download: Data Folder, Data Set Description Abstract: The data is related with direct marketing campaigns (phone calls) of a Portuguese banking institution. The classification goal is to predict if the client will subscribe a term d
archive.ics.uci.edu
엑셀에서 피벗테이블을 사용하는 과정
- 값, 행, 열영역에 사용할 칼럼을 드래그&드롭한다.
- 그리고 값 영역을 클릭하여 값필드설정에 들어간다.
- 거기에서 데이터를 요약할 집계함수를 선택한다.
파이썬의 피벗테이블 함수
# pd.pivot_table(데이터프레임, values=’값’, index=’행’, columns=’열’, aggfunc=’집계함수명’)
피벗테이블 함수 다루기
import pandas as pd
import pandas
import matplotlib.pyplot as plt
df=pd.read_csv('bank-additional-full.csv',sep=';')
pd.pivot_table(df,values='duration',index='y',columns='contact',aggfunc='mean')
# 데이터프레임 타입으로 반환
pt_type=pd.pivot_table(df,values='duration',index='y',columns='contact',aggfunc='mean')
type(pt_type)
#output: pandas.core.frame.DataFrame
매개변수 입력없이 피벗테이블 만들기
pd.pivot_table(df,'duration','y','contact','mean')
다중 행 인덱스 설정
pd.pivot_table(df,'duration',['y','poutcome'],'contact','mean')
다중 열 인덱스 설정
pd.pivot_table(df,'duration',['y','poutcome'],['job','contact'],'mean')
결측값 처리
pd.pivot_table(df,'duration',
['y','poutcome'],['job','contact'],
aggfunc='mean',fill_value=0)
320x100
320x100
'빅데이터 관련 자료 > Python' 카테고리의 다른 글
파이썬 기초용어 정리 - 제어문, 입출력 etc (0) | 2022.01.05 |
---|---|
Python 기초 용어 정리 - 자료형 (0) | 2022.01.04 |
index_col, 원하는 컬럼을 인덱스로 지정하여 불러오기 (0) | 2021.10.25 |
파이썬 기초 - 6 (0) | 2021.08.02 |
파이썬 기초 - 5 (0) | 2021.07.29 |