목표¶
- 아이템별 지표 확인하기
- 시간별 지역별 판매 지표 확인하기
In [1]:
import numpy as np
import pandas as pd
# seaborn
import seaborn as sns
COLORS = sns.color_palette()
import matplotlib as plt
%matplotlib inline
데이터 로딩¶
- 정제된 데이터 사용(retail.csv)
In [2]:
dtypes = {
'UnitPrice': np.float32,
'CustomerID': np.int32,
'Quantity': np.int32
}
retail = pd.read_csv('./OnlineRetailClean.csv', dtype=dtypes)
retail.head()
Out[2]:
날짜 타입 데이터 변환¶
- 문자열로 로딩하는 것보다 date/datetime 타입으로 로딩하는 것이 분석에 용이
In [3]:
retail['InvoiceDate']=pd.to_datetime(retail['InvoiceDate'],infer_datetime_format=True)
retail.head()
Out[3]:
해당 기간 동안의 매출¶
- 전체 매출
- 국가별 매출
- 월별 매출
- 요일별 매출
- 시간별 매출
전체 매출¶
In [4]:
total_revenue=retail['CheckoutPrice'].sum()
total_revenue
Out[4]:
국가별 매출¶
In [5]:
rev_by_countries=retail.groupby('Country').sum()['CheckoutPrice'].sort_values()
rev_by_countries
Out[5]:
In [6]:
plot=rev_by_countries.plot(kind='bar',figsize=(20,10))
plot.set_xlabel('Country',fontsize=11)
plot.set_ylabel('Revenue',fontsize=11)
plot.set_title('Revenue by Country', fontsize=13)
plot.set_xticklabels(labels=rev_by_countries.index, rotation=45)
Out[6]:
In [7]:
plot=(rev_by_countries/total_revenue).plot(kind='pie',figsize=(20,10))
그래프 유틸 함수¶
In [8]:
def plot_bar(df, xlabel,ylabel,title,color=COLORS[0], figsize=(30,10), rotation=45):
plot=df.plot(kind='bar')
plot.set_xlabel(xlabel,fontsize=11)
plot.set_ylabel(ylabel,fontsize=11)
plot.set_title(title, fontsize=13)
plot.set_xticklabels(labels=df.index, rotation=rotation)
plot_bar(rev_by_countries,'Country','Revenue','Revenue by Country')
'머신러닝' 카테고리의 다른 글
파이썬_캐글(kaggle) 타이타닉 생존 예측 (점수 77% 달성 후기) (0) | 2020.09.21 |
---|---|
파이썬_쇼핑몰 매출 분석2 (월별,요일별,시간별 매출 분석, top 판매 제품, top매출 아이템 판매량 추이 분석) (0) | 2020.09.21 |
파이썬_쇼핑몰 고객 주문 데이터 분석 (판매 데이터 파악, 데이터 정제) (2) | 2020.09.20 |
파이썬_캐글(kaggle) 로지스틱 회귀분석(logistic regression) 활용한 타이타닉 생존 예측 (0) | 2020.09.20 |
파이썬_캐글(kaggle) 의사결정나무(decision tree) 활용한 타이타닉 생존 예측 (0) | 2020.09.20 |