<jupyter_start><jupyter_text>웹 주문 수 분석* customer_master.csv : 쇼핑몰 사이트 고객 정보* item_master.csv : 상품 데이터(상품명, 가격)* transaction_1.csv, transaction_1.csv : 구매내역 데이터* transaction_detail_1.csv, transaction_detail_1.csv : 구매내역 상세 데이터  1. 데이터 읽기<jupyter_code>import pandas as pd

customer_master = pd.read_csv('customer_master.csv')
customer_master.head()
item_master = pd.read_csv('item_master.csv')
item_master.head()
transaction_1 = pd.read_csv('transaction_1.csv')
transaction_1.head()
transaction_detail_1 = pd.read_csv('transaction_detail_1.csv')
transaction_detail_1.head()<jupyter_output><empty_output><jupyter_text>2. 데이터 결합* 데이터 전체를 파악하는 것이 중요* 상세한 데이터를 기준으로 맞추어 데이터를 결합/가공<jupyter_code># transaction_1, transaction_2 결합
transaction_2 = pd.read_csv('transaction_2.csv')

transaction = pd.concat([transaction_1, transaction_2], ignore_index=True)
transaction.head()
print(transaction_1.shape)
print(transaction_2.shape)
print(transaction.shape)
# transaction_detail
transaction_detail_2 = pd.read_csv('transaction_detail_2.csv')

transaction_detail = pd.concat([transaction_detail_1, transaction_detail_2], ignore_index=True)
transaction_detail.head()
print(transaction_detail_1.shape)
print(transaction_detail_2.shape)
print(transaction_detail.shape)<jupyter_output>(5000, 4)
(2144, 4)
(7144, 4)<jupyter_text>3. 매출 데이터 결합(join)* transaction_detail 기준* 데이터 join시 부족한 컬럼은 무엇인지, 공통되는 데이터 컬럼은 무엇인지 파악      추가 : payment_date, customer_id / 공통 : transaction_id<jupyter_code>join_data = pd.merge(transaction_detail, transaction[['transaction_id', 'payment_date', 'customer_id']],
                    on = 'transaction_id', how='left')
join_data.head()
print(transaction_detail.shape)
print(transaction.shape)
print(join_data.shape)<jupyter_output>(7144, 4)
(6786, 4)
(7144, 6)<jupyter_text>4. 마스터데이터 결합(join)* 추가 : customer_master, item_master / 공통 : customer_id, item_id<jupyter_code>join_data = pd.merge(join_data, customer_master, on='customer_id', how='left')
join_data = pd.merge(join_data, item_master, on='item_id', how='left')
join_data.head()<jupyter_output><empty_output><jupyter_text>5. 필요 데이터 생성* price = quantity * item_price<jupyter_code>join_data['price'] = join_data['quantity'] * join_data['item_price']
join_data[['quantity', 'item_price', 'price']].head()<jupyter_output><empty_output><jupyter_text>6. 계산 확인<jupyter_code>print(join_data['price'].sum())
print(transaction['price'].sum())
join_data['price'].sum() == transaction['price'].sum()<jupyter_output><empty_output><jupyter_text>7. 통계량 파악* 데이터 분석 시 먼저 파악해야할 숫자      결측치의 개수, 전체 숫자<jupyter_code>join_data.isnull().sum()
join_data.describe()<jupyter_output><empty_output><jupyter_text>* 추가 확인 : 데이터의 기간<jupyter_code>print(join_data['payment_date'].min())
print(join_data['payment_date'].max())<jupyter_output>2019-02-01 01:36:57
2019-07-31 23:41:38<jupyter_text>8. 월별 데이터 집계 * 각 컬럼의 데이터타입 확인<jupyter_code>join_data.dtypes<jupyter_output><empty_output><jupyter_text>* payment_date의 타입 변경 : object -> datetime<jupyter_code>join_data['payment_date'] = pd.to_datetime(join_data['payment_date'])
join_data['payment_month'] = join_data['payment_date'].dt.strftime('%Y%m')
join_data[['payment_date', 'payment_month']].head()<jupyter_output><empty_output><jupyter_text>* 월별 매출 합계<jupyter_code>join_data.groupby('payment_month').sum()['price']<jupyter_output><empty_output><jupyter_text>9. 월별, 상품별 데이터 집계<jupyter_code>join_data.groupby(['payment_month', 'item_name']).sum()[['price', 'quantity']]
pd.pivot_table(join_data, index='item_name', columns='payment_month', values=['price', 'quantity'], aggfunc='sum')<jupyter_output><empty_output><jupyter_text>10. 상품별 매출 추이 가시화<jupyter_code>graph_data = pd.pivot_table(join_data, index='payment_month', columns='item_name', values='price', aggfunc='sum')
graph_data.head()
import matplotlib.pyplot as plt
%matplotlib inline

plt.plot(list(graph_data.index), graph_data['PC-A'], label='PC-A')
plt.plot(list(graph_data.index), graph_data['PC-B'], label='PC-B')
plt.plot(list(graph_data.index), graph_data['PC-C'], label='PC-C')
plt.plot(list(graph_data.index), graph_data['PC-D'], label='PC-D')
plt.plot(list(graph_data.index), graph_data['PC-E'], label='PC-E')
plt.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15624256837098693, 'fraction_numerical': 0.02211652794292509, 'mean_word_length': 9.28361858190709, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '174069', 'license': 'MIT', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1994, 'n_words': 237, 'path': '[분석실무]1.웹주문분석.ipynb', 'repo_name': 'kamzzang/ADPStudy', 'size': '4205'}