-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathanalysis_of_sales_channel.py
45 lines (33 loc) · 1.48 KB
/
analysis_of_sales_channel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import pandas as pd
folder_path = '.\\excel\\'
def get_sales_data(path):
# フォルダの中のファイルをすべて取り出す
excel_files = os.listdir(path)
# Excelファイルの中のデータを取り出すためのリストを定義
list_sales_data = []
# Excelファイルの売上データを取り出す
for excel_file in excel_files:
if '売上' in excel_file:
sales_data = pd.read_excel(path + excel_file)
list_sales_data.append(sales_data)
# 取り出した売上データを連結する
sales_summary = pd.concat(list_sales_data, ignore_index=True)
return sales_summary
def get_channel_data(path):
# 取引先流入元データをpandasで読み込む
sales_channel = pd.read_excel(path + '取引先流入元.xlsx')
return sales_channel
# 売上データと流入元データを取得
sales = get_sales_data(folder_path)
channel = get_channel_data(folder_path)
# 流入元データと、売上サマリーデータを結合する
sales_summary = pd.merge(channel, sales, on='取引先名')
# 流入元ごとの売上データを集計
sales_by_channel = sales_summary.groupby('流入元').sum()
# 流入元ごとの売上データを出力
print(sales_by_channel)
# Excelに集計したデータを出力
with pd.ExcelWriter('summary.xlsx') as writer:
sales_summary.to_excel(writer, sheet_name='売上サマリー')
sales_by_channel.to_excel(writer, sheet_name='流入元ごとの売上')