이전 글에서 설명했던 melt()와는 반대되는 피봇에 대해 알아보자
실습 데이터는 아래와 같다.

long형 데이터를 내가 보고싶은 데이터만 가지고 wide하게 만들어
데이터를 보기 더 편하게 만듦
연도를 기준으로 사원들의 연도별매출 피봇
company.pivot(index='연도', columns='사원이름', values='연도별매출')

사람을 기준으로 연도별 매출 피봇
‘이 사람이 갈 수록 일을 어떻게 하는지 알아보자’
company.pivot(index='사원이름', columns='연도', values='연도별매출')

이 두 인자는 선택값이다.
index=를 안적으면 원본데이터의 index를 가져온다.
set_index 처럼 먼저 인덱스를 지정했을 때!values=를 안적으면 모든 값을 가져오게 된다.
values=를 안적을 때 실습
```python
# values를 생략하면 모든 열이 사용됨
company.pivot(index='사원이름', columns='연도')
```

멀티 인덱싱이 됨.
회사 연도를 기준으로 사원들의 매출을 볼 수 있게 피봇 후 melt() 해보자.
company_pivot = company.pivot(index='연도', columns='사원이름',values='연도별매출')

이를 melt()화 해보자
연도를 기준으로 long형태의 데이터를 만들어보려고 한다.
company_pivot.melt(id_vars='연도',value_name='연도별매출')

오잉!? 에러가 발생했다.
그 이유는 company_pivot 에 로우 인덱스가 되어 있기 때문이다.
reset_index()로 인덱스 제거 후 다시 진행해 보자.
company_pivot.reset_index().melt(id_vars='연도',value_name='연도별매출')

이 처럼 pivot()과 melt()는 반대되는 개념인 것을 알 수 있었다.
피봇테이블은 피봇과 마찬가지로 우리가 보고싶은 걸 보는데,
다른점은 집계함수를 쓴다는 것이다.(aggfunc= 인자를 사용 default값은 mean이다.)
parameter
values: list-like or scalar, optional⭐index: column, Grouper, array, or list of the previouscolumns: column, Grouper, array, or list of the previous⭐aggfunc: function, list of functions, dict, default “mean”⭐fill_value : scalar, default Nonemargins : bool, default Falsedropna : bool, default Truemargins_name : str, default ‘All’observed : bool, default Falsesort : bool, default True다양한 예제를 통해 이해해보자
pivot_table 예제
# 사원별 누적매출 통계내기
company.pivot_table(values='연도별매출',columns='사원이름',aggfunc='sum')

pivot때와 다르게 pivot_table은 집계한게 나오기 때문에 index를 지정해주지 않는 모습
또한 인덱스 값이 자동으로 ‘연도별매출’로 들어오게 된다.
company.pivot_table(values='연도별매출',columns='연도',aggfunc='mean')
aggfunc= 인자 default는 mean이기 때문에 생략 가능

# 소속팀별 연도별매출 평균을 확인하기
company.pivot_table(values='연도별매출',columns='소속팀')

값은 매출
컬럼은 소속팀
인덱스로 연도가 들어가야 된다. 이때 사용하는 인자가 index= 이다.
company.pivot_table(values='연도별매출',index='연도',columns='소속팀')

"A별 BB의 CCC함수값을 DDDD인덱스로 확인하기"
A별 -> columns
BB의 -> values
CCC함수값을 -> aggfunc
DDDD인덱스로 -> index
pivot()과 pivot_table()의 차이.
pivot()은 가지고 오고 싶은 데이터를 wide하게 만듦
pivot_table() 가지고 오고 싶은 데이터를 집계 후 wide하게 만듦