빅데이터(파이썬)/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)
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')
OVERVIEW
PRODUCT_CODE
WAREHOUSE
PRODCT_CATEGORY
DATE
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