-
<Python> 2020_06_05 코드 정리데이터 분석 공부 2020. 6. 5. 20:11
retail['InvoiceDate'] = pd.to_datetime(retail['InvoiceDate'], infer_datetime_format=True) retail.info() plot = rev_by_countries.plot(kind='bar', color=COLORS[-1], 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) def extract_month(date): month = str(date.month) if date.month < 10: month = '0' + month return str(date.year) + month rev_by_month = retail.set_index('InvoiceDate').groupby(extract_month).sum()['CheckoutPrice'] rev_by_month plot_bar(rev_by_month, 'Month', 'Revenue', 'Revenue by Month') rev_by_dow = retail.set_index('InvoiceDate').groupby(lambda date:date.dayofweek).sum()['CheckoutPrice'] rev_by_dow DAY_OF_WEEK = np.array(['Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']) rev_by_dow.index = DAY_OF_WEEK[rev_by_dow.index] plot_bar(rev_by_dow, 'DOW', 'Revenue', 'Revenue by DOW')
#### 우수 고객 확인
- 구매 횟수 기준
- 지불 금액 기준retail.groupby('CustomerID').count()['Quantity'].sort_values(ascending=False) retail.groupby('CustomerID').sum()['CheckoutPrice'].sort_values(ascending=False) def get_month_as_datetime(date): return datetime(date.year, date.month, 1) xticks = np.arange(0, 13) yticks = ['2010/12', '2011/01', '2011/02', '2011/03', '2011/04', '2011/05', '2011/06', '2011/07', '2011/08', '2011/09', '2011/10', '2011/11', '2011/12'] plt.figure(figsize = (15, 8)) sns.heatmap(customer_cohort, annot=True, xticklabels=xticks, yticklabels=yticks, fmt='.1f')
'데이터 분석 공부' 카테고리의 다른 글
<SQL> Programmers_GROUP BY_고양이와 개는 몇 마리 있을까? (0) 2020.07.29 미래의 동영상 서비스에 대한 기획서 작성 (0) 2020.06.10 <Python> 오늘 공부한 코드 정리 (0) 2020.06.05 [Python] csv파일 불러올 때, 한글 깨짐 현상 해결(feat. Mac) (0) 2020.05.25 [Python] L.Point 데이터 다뤄보기 (1) 2020.05.24