빅데이터(파이썬)/DA_Forecasts for Product Demand

Forecasts for Product Demand (1) EDA 레포트 생성, 데이터 변환/추가

LearnerToRunner 2022. 12. 27. 20:45

Forecasts for Product Demand

데이터셋 구성을 확인하기 위한 EDA 레포트 생성 및 데이터 변환/추가

 

데이터 타입 확인하기

import pandas as pd

df = pd.read_csv('./archive/Historical Product Demand.csv')
print(df.dtypes)
print(df.columns)

5개의 칼럼


pandas_profiling을 이용해서 레포트 생성하기

import pandas as pd
from pandas_profiling import ProfileReport

df = pd.read_csv('./archive/Historical Product Demand.csv')
profile = ProfileReport(df= df, explorative=True)
profile.to_file('pd_profile.html')

 

pd_profile.html 생성

 

OVERVIEW

전체 데이터셋 중 결측치가 11,239개, 중복값이 84,521개 있다


PRODUCT_CODE

가장 많은 프로덕트가 1.6%를 구성. 제품 데이터는 어느정도 균일하게 있는 듯하다.

 


WAREHOUSE

웨어하우스 J의 데이터 수가 72%로 가장 많다. 이후 A>S>C


PRODCT_CATEGORY

카테고리 19의 데이터가 전체의 45.9%를 구성한다.


DATE

데이터의 날짜 수는 일정한듯하다. 다만, 전체의 1.1%에 해당하는 결측치가 11,239 존재한다.


ORDER_DEMAND

 


데이터 타입 변환하기

Product_Code (str)

>> 'Product_' 삭제 후 int로 전환

 

Warehouse (str)

>> 'Whse_' 삭제

 

Product_Category (str)

>> 'Category_' 삭제 후 int로 전환

 

Date (str)

>> datetime 타입으로 변환 (read_csv에서 처리)

 

Order_Demand (str)

>> 음수를 표시하는 ()를 제거 후 -(negative)로 전환

>> int 타입으로 변환

 

# 데이터를 불러올 때 날짜 칼럼을 date형태로 변환
df = pd.read_csv('./archive/Historical Product Demand.csv', parse_dates=['Date'])
"""
Data Conversion
"""
# Product_Code 
df['Product_Code'] = df['Product_Code'].str.replace('Product_', '').astype(int)
# Warehouse
df['Warehouse'] = df['Warehouse'].str.replace('Whse_', '')

# Product_Category
df['Product_Category'] = df['Product_Category'].str.replace('Category_', '').astype(int)

# Order Demand
df['Order_Demand'] = df['Order_Demand'].replace('[)]', '', regex=True)
df['Order_Demand'] = df['Order_Demand'].replace('[(]', '-', regex=True)
df['Order_Demand'] = df['Order_Demand'].astype(int)

 


시계열 데이터 분석을 용이하게 하기 위해 연, 월, 주, 요일 데이터를 추가

연, 월, 요일이 float 64형태로 나와서 변환 가능한 int16 타입으로 바꾸었음

'''
Time Data 
'''
df['Year'] = df['Date'].dt.year.astype('Int16') #연도
df['Month'] = df['Date'].dt.month.astype('Int16') # 월
df['Week'] = df['Date'].dt.isocalendar().week # 주 (week of the year)
df['DayOW'] = df['Date'].dt.dayofweek.astype('Int16') #요일 (day of the week) FYI) Mon 0 - Sun = 6

print(df[['Date', 'Year', 'Month', 'Week', 'DayOW']])


TO-DOs
데이터 시각화, 결측치 처리, 중복 데이터 처리

 

728x90