하나의 데이터셋으로 만드는 과정!
👉 환경 설정
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
1. pd.concat
데이터 프레임 구조에 맞게 합치기 - 인덱스, 열 기준
pd.concat([df1, df2], axis = 0, join = 'inner', ignore_index=True)
데이터프레임에 ' '를 붙이지 않음
- axis
axis = 0 : 행으로 붙임(세로로 붙임)
axis = 1 : 열로 붙임(가로로 붙임)
- join
outer : 모든 행,열 합치기
inner : 같은 행,열 합치기
- ignore_index=True
기존의 행 번호 무시하기
2. pd.merge
지정한 값을 기준으로 합치기!(Join과 비슷) - 특정 열기준
- on을 사용하지 않아도 칼럼이름이 같으면 생략이 가능하다.
- 옆으로만 병합하며 두개의 df만 결합이 가능하다.
pd.merge(df1, df2, how = 'inner', on = 'A') #inner가 디폴트
일별, 카테고리별 판매량 합계
pd.merge(sales1,products,how='inner').groupby(['Date','Category'],as_index=False)['Qty'].sum()
3. pd.pivot
결합은 아니지만, 집계 후 데이터프레임 구조를 변형해서 조회
1. 집계
temp2 = temp.groupby(['Date', 'Category'], as_index = False)['Qty'].sum()
temp2
2. pivot
temp2.pivot(index = 'Category', columns= 'Date' , values ='Qty')
4. heatmap
import matplotlib.pyplot as plt
import seaborn as sns
# plt.figure(figsize = (20, 6))
sns.heatmap(temp3)
# plt.show()
'KT AIVLE School > 데이터 처리 및 분석' 카테고리의 다른 글
단변량 분석 - 숫자형 (0) | 2024.09.10 |
---|---|
시각화 라이브러리 (0) | 2024.09.10 |
데이터분석 방법론 (0) | 2024.09.10 |
시계열 데이터 처리 (0) | 2024.09.09 |
데이터프레임 변경 (0) | 2024.09.09 |