제로베이스 데이터취업스쿨 DAY20 EDA 범죄1~2

NAYOUNG KIM·2023년 3월 29일
0

제로베이스 교육

목록 보기
20/54
post-thumbnail

피벗테이블

1) index

  • pd.pivot_table(df, index=["Name"])
  • pd.pivot_table(df, index=["Name","Rep","Manager"])

2) index, values

  • pd.pivot_table(df, index=["Name"], values=["Price"])
    (평균이 디폴트)

3) index, values, aggfunc

  • pd.pivot_table(df, index=["Name"], values=["Price"], aggfunc=np.sum)
  • pd.pivot_table(df, index=["Name"], values=["Price"], aggfunc=[np.sum, len])
    (len : 개수)

4) index, values, aggfunc, columns
(columns : 분류 지정)

  • pd.pivot_table(df, index=["Name", "Rep"], values=["Price"], columns=["Product"], aggfunc=[np.sum])

5) index, values, aggfunc, columns, fill_value

  • pd.pivot_table(df, index=["Name", "Rep"], values=["Price"], columns=["Product"], aggfunc=[np.sum], fill_value=0)

6) pivot(인덱스, 열, value)

  • flights = flights.pivot("month","year","passengers")

7) 다중컬럼
crime_station.columns = crime_station.columns.droplevel([0,1])
crime_station.columns.get_level_values(0)



profile
21세기 주인공

0개의 댓글