{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\n\n# 데이터 경로\ndata_path = '/kaggle/input/competitive-data-science-predict-future-sales/'\n\nsales_train = pd.read_csv(data_path + 'sales_train.csv')\nshops = pd.read_csv(data_path + 'shops.csv')\nitems = pd.read_csv(data_path + 'items.csv')\nitem_categories = pd.read_csv(data_path + 'item_categories.csv')\ntest = pd.read_csv(data_path + 'test.csv')\nsubmission = pd.read_csv(data_path + 'sample_submission.csv')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-13T09:31:04.348749Z","iopub.execute_input":"2022-08-13T09:31:04.349162Z","iopub.status.idle":"2022-08-13T09:31:06.872038Z","shell.execute_reply.started":"2022-08-13T09:31:04.349121Z","shell.execute_reply":"2022-08-13T09:31:06.870824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"sales_train.csv - 교육 세트. 2013년 1월부터 2015년 10월까지의 일일 이력 데이터.\\\ntest.csv - 테스트 세트. 당신은 2015년 11월 이 가게들과 상품들의 매출을 예측해야 합니다.\\\nsample_submission.csv - 올바른 형식의 샘플 제출 파일입니다.\\\nitems.csv - 항목/제품에 대한 보충 정보.\\\nitem_categories.csv - 항목 범주에 대한 추가 정보입니다.\\\nshops.csv-shops에 대한 추가 정보입니다.","metadata":{}},{"cell_type":"markdown","source":"ID - 테스트 세트 내의 (샵, 아이템) 튜플을 나타내는 ID\\\nshop_id - 상점의 고유 식별자\\\nitem_id - 제품의 고유 식별자\\\nitem_filename_id - 품목 카테고리의 고유 식별자\\\nitem_cnt_day - 판매된 제품 수입니다. 이 측정의 월별 금액을 예측하고 있습니다.\\\nitem_price - 품목의 현재 가격\\\ndate - dd/mm/yyyy 형식의 날짜\\\ndate_block_num - 편의를 위해 사용되는 연속된 월 번호입니다. 2013년 1월 0일 2013년 2월 1, ... 2015년 10월 33일\\\nitem_name - 항목 이름\\\nshop_name - 상점 이름\\\nitem_filename_name - 품목 카테고리 이름","metadata":{}},{"cell_type":"code","source":"sales_train.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:06.874002Z","iopub.execute_input":"2022-08-13T09:31:06.874651Z","iopub.status.idle":"2022-08-13T09:31:06.903794Z","shell.execute_reply.started":"2022-08-13T09:31:06.874612Z","shell.execute_reply":"2022-08-13T09:31:06.902420Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sales_train.info(show_counts=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:06.905380Z","iopub.execute_input":"2022-08-13T09:31:06.906414Z","iopub.status.idle":"2022-08-13T09:31:07.084697Z","shell.execute_reply.started":"2022-08-13T09:31:06.906370Z","shell.execute_reply":"2022-08-13T09:31:07.083437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shops.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:07.087224Z","iopub.execute_input":"2022-08-13T09:31:07.087700Z","iopub.status.idle":"2022-08-13T09:31:07.099072Z","shell.execute_reply.started":"2022-08-13T09:31:07.087664Z","shell.execute_reply":"2022-08-13T09:31:07.097753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shops.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:07.100646Z","iopub.execute_input":"2022-08-13T09:31:07.101049Z","iopub.status.idle":"2022-08-13T09:31:07.117617Z","shell.execute_reply.started":"2022-08-13T09:31:07.101015Z","shell.execute_reply":"2022-08-13T09:31:07.116234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"items.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:07.119322Z","iopub.execute_input":"2022-08-13T09:31:07.120445Z","iopub.status.idle":"2022-08-13T09:31:07.136936Z","shell.execute_reply.started":"2022-08-13T09:31:07.120404Z","shell.execute_reply":"2022-08-13T09:31:07.135582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"items.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:07.138404Z","iopub.execute_input":"2022-08-13T09:31:07.139351Z","iopub.status.idle":"2022-08-13T09:31:07.158871Z","shell.execute_reply.started":"2022-08-13T09:31:07.139298Z","shell.execute_reply":"2022-08-13T09:31:07.157541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"item_categories.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:07.160409Z","iopub.execute_input":"2022-08-13T09:31:07.161443Z","iopub.status.idle":"2022-08-13T09:31:07.171150Z","shell.execute_reply.started":"2022-08-13T09:31:07.161404Z","shell.execute_reply":"2022-08-13T09:31:07.170241Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"item_categories.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:07.172636Z","iopub.execute_input":"2022-08-13T09:31:07.173379Z","iopub.status.idle":"2022-08-13T09:31:07.191999Z","shell.execute_reply.started":"2022-08-13T09:31:07.173333Z","shell.execute_reply":"2022-08-13T09:31:07.190932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:07.195258Z","iopub.execute_input":"2022-08-13T09:31:07.195646Z","iopub.status.idle":"2022-08-13T09:31:07.208951Z","shell.execute_reply.started":"2022-08-13T09:31:07.195610Z","shell.execute_reply":"2022-08-13T09:31:07.207798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = sales_train.merge(shops, on='shop_id', how='left')\ntrain = train.merge(items, on='item_id', how='left')\ntrain = train.merge(item_categories, on='item_category_id', how='left')\n\ntrain.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:07.210636Z","iopub.execute_input":"2022-08-13T09:31:07.211224Z","iopub.status.idle":"2022-08-13T09:31:09.086686Z","shell.execute_reply.started":"2022-08-13T09:31:07.211186Z","shell.execute_reply":"2022-08-13T09:31:09.085313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def resumetable(df):\n    print(f'데이터 세트 형상: {df.shape}')\n    summary = pd.DataFrame(df.dtypes, columns=['데이터 타입'])\n    summary = summary.reset_index()\n    summary = summary.rename(columns={'index': '피처'})\n    summary['결측값 개수'] = df.isnull().sum().values\n    summary['고윳값 개수'] = df.nunique().values\n    summary['첫 번째 값'] = df.loc[0].values\n    summary['두 번째 값'] = df.loc[1].values\n    \n    return summary","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:09.088165Z","iopub.execute_input":"2022-08-13T09:31:09.088588Z","iopub.status.idle":"2022-08-13T09:31:09.096585Z","shell.execute_reply.started":"2022-08-13T09:31:09.088552Z","shell.execute_reply":"2022-08-13T09:31:09.095238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resumetable(train)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:09.098755Z","iopub.execute_input":"2022-08-13T09:31:09.099899Z","iopub.status.idle":"2022-08-13T09:31:11.411071Z","shell.execute_reply.started":"2022-08-13T09:31:09.099847Z","shell.execute_reply":"2022-08-13T09:31:11.409763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\nsns.boxplot(y='item_cnt_day', data=train);","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:11.412354Z","iopub.execute_input":"2022-08-13T09:31:11.412711Z","iopub.status.idle":"2022-08-13T09:31:12.857546Z","shell.execute_reply.started":"2022-08-13T09:31:11.412678Z","shell.execute_reply":"2022-08-13T09:31:12.856345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(y='item_price', data=train);","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:12.858908Z","iopub.execute_input":"2022-08-13T09:31:12.859263Z","iopub.status.idle":"2022-08-13T09:31:13.624730Z","shell.execute_reply.started":"2022-08-13T09:31:12.859225Z","shell.execute_reply":"2022-08-13T09:31:13.623471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"group = train.groupby('date_block_num').agg({'item_cnt_day': 'sum'})\ngroup.reset_index() # 인덱스 재설정","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:13.626029Z","iopub.execute_input":"2022-08-13T09:31:13.626370Z","iopub.status.idle":"2022-08-13T09:31:13.709773Z","shell.execute_reply.started":"2022-08-13T09:31:13.626338Z","shell.execute_reply":"2022-08-13T09:31:13.708388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rc('font', size=13)\nfigure, ax = plt.subplots() \nfigure.set_size_inches(11, 5)\n\n# 월별 총 상품 판매량\ngroup_month_sum = train.groupby('date_block_num').agg({'item_cnt_day': 'sum'})\ngroup_month_sum = group_month_sum.reset_index()\n\n# 월별 총 상품 판매량 막대그래프\nsns.barplot(x='date_block_num', y='item_cnt_day', data=group_month_sum)\n# 그래프 제목, x축 라벨, y축 라벨명 설정\nax.set(title='Distribution of monthly item counts by date block number',\n       xlabel='Date block number', \n       ylabel='Monthly item counts');","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:13.711843Z","iopub.execute_input":"2022-08-13T09:31:13.712273Z","iopub.status.idle":"2022-08-13T09:31:14.262450Z","shell.execute_reply.started":"2022-08-13T09:31:13.712232Z","shell.execute_reply":"2022-08-13T09:31:14.260971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"연말 판매량 증가가 눈에 보인다.\\\n전체적인 판매량의 흐름은 감소하는 것 같은데..?","metadata":{}},{"cell_type":"code","source":"figure, ax= plt.subplots() \nfigure.set_size_inches(11, 5)\n\n# 상품분류별 총 상품 판매량\ngroup_cat_sum = train.groupby('item_category_id').agg({'item_cnt_day': 'sum'})\ngroup_cat_sum = group_cat_sum.reset_index()\n\n# 총 판매량이 10,000개를 초과하는 상품분류만 추출\ngroup_cat_sum = group_cat_sum[group_cat_sum['item_cnt_day'] > 10000]\n\n# 상품분류별 총 상품 판매량 막대그래프\nsns.barplot(x='item_category_id', y='item_cnt_day', data=group_cat_sum)\nax.set(title='Distribution of total item counts by item category id',\n       xlabel='Item category ID', \n       ylabel='Total item counts')\nax.tick_params(axis='x', labelrotation=90) # x축 라벨 회전","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:14.264215Z","iopub.execute_input":"2022-08-13T09:31:14.264865Z","iopub.status.idle":"2022-08-13T09:31:14.863708Z","shell.execute_reply.started":"2022-08-13T09:31:14.264814Z","shell.execute_reply":"2022-08-13T09:31:14.862490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"상품분류별 판매가 차이가 매우 크다.","metadata":{}},{"cell_type":"code","source":"figure, ax= plt.subplots() \nfigure.set_size_inches(11, 5)\n\n# 상점별 총 상품 판매량\ngroup_shop_sum = train.groupby('shop_id').agg({'item_cnt_day': 'sum'})\ngroup_shop_sum = group_shop_sum.reset_index()\n\ngroup_shop_sum = group_shop_sum[group_shop_sum['item_cnt_day'] > 10000]\n\n# 상점별 총 상품 판매량 막대그래프\nsns.barplot(x='shop_id', y='item_cnt_day', data=group_shop_sum)\nax.set(title='Distribution of total item counts by shop id',\n       xlabel='Shop ID', \n       ylabel='Total item counts')\nax.tick_params(axis='x', labelrotation=90)","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:31:14.864997Z","iopub.execute_input":"2022-08-13T09:31:14.866069Z","iopub.status.idle":"2022-08-13T09:31:15.648585Z","shell.execute_reply.started":"2022-08-13T09:31:14.866029Z","shell.execute_reply":"2022-08-13T09:31:15.647360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"상점별 판매량도 차이가 매우 크다.","metadata":{}},{"cell_type":"code","source":"train[train['shop_id']==31] ","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:34:46.773094Z","iopub.execute_input":"2022-08-13T09:34:46.773550Z","iopub.status.idle":"2022-08-13T09:34:46.819515Z","shell.execute_reply.started":"2022-08-13T09:34:46.773486Z","shell.execute_reply":"2022-08-13T09:34:46.818658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"31번 샵은 게임판매하는 곳","metadata":{}},{"cell_type":"code","source":"train[train['item_cnt_day']>999]","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:36:23.249062Z","iopub.execute_input":"2022-08-13T09:36:23.249466Z","iopub.status.idle":"2022-08-13T09:36:23.269713Z","shell.execute_reply.started":"2022-08-13T09:36:23.249431Z","shell.execute_reply":"2022-08-13T09:36:23.268393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"1000개짜리는 특정 브랜드 패키지 상품인듯\n2169개짜리는 배송 서비스인 것 같음.","metadata":{}},{"cell_type":"code","source":"train[train['item_price']>49999]","metadata":{"execution":{"iopub.status.busy":"2022-08-13T09:39:33.770865Z","iopub.execute_input":"2022-08-13T09:39:33.771388Z","iopub.status.idle":"2022-08-13T09:39:33.794948Z","shell.execute_reply.started":"2022-08-13T09:39:33.771331Z","shell.execute_reply":"2022-08-13T09:39:33.793871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"59200루블 배달?\\\n307980루블 소프트 웨어같은데?\\\nRC가 비상이라니까 긴급 배송같은건가 그래서 좀 비싼가\\\n다른 하나는 쇼핑센터에서 파는 단체 체스판인듯\n전부 단체 구매 상품인것 같다.","metadata":{}}]}