taskforce-dev commited on
Commit
3085988
·
1 Parent(s): 4aaa3d2

Delete sundry.py

Browse files
Files changed (1) hide show
  1. sundry.py +0 -63
sundry.py DELETED
@@ -1,63 +0,0 @@
1
- import pandas as pd
2
- import gradio as gr
3
-
4
- # 関数を定義
5
- def process_csv(input_file):
6
-
7
- # Load the CSV file with MS932 encoding
8
- df = pd.read_csv(input_file.name, encoding="MS932", header=0)
9
-
10
- # Insert '行形式' column twice at the beginning
11
- for _ in range(2):
12
- if '行形式' not in df.columns:
13
- df.insert(0, '行形式', '')
14
-
15
- # Drop specified columns
16
- columns_to_drop = ['伝票連番', '連番行番号', '行番号', '伝票区分', '商品コード', '商品名区分',
17
- '売上数量_在庫用数量', '売上金額', '形番号', 'ユーザーNO1', '得意先名', '郵便番号',
18
- '住所1', '住所2', '電話番号', '受注_図面番号', '受注_サイズ']
19
- df.drop(columns_to_drop, axis=1, inplace=True, errors='ignore')
20
-
21
- # Rename specified columns
22
- column_name_mapping = {
23
- '伝票日付': '請求日',
24
- '伝票番号': '請求番号',
25
- '商品名': '品名',
26
- '売上数量_請求用数量': '数量',
27
- '売上単価': '単価',
28
- '行摘要': '件名',
29
- '受注_備考': 'メモ'
30
- }
31
- df.rename(columns=column_name_mapping, inplace=True)
32
-
33
- # Group by '請求番号' and modify rows
34
- df_grouped = df.groupby('請求番号')
35
- dfs = []
36
-
37
- for _, group in df_grouped:
38
- header_row = group.iloc[0].copy()
39
- new_group = pd.concat([header_row.to_frame().T, group])
40
- new_group.iloc[0, new_group.columns.get_loc('行形式')] = 'ヘッダ'
41
- new_group.iloc[1:, new_group.columns.get_loc('行形式')] = '明細'
42
- new_group.iloc[0, new_group.columns.get_loc('品名')] = ''
43
- new_group.iloc[0, new_group.columns.get_loc('数量')] = ''
44
- new_group.iloc[0, new_group.columns.get_loc('単価')] = ''
45
- new_group.iloc[0, new_group.columns.get_loc('単位')] = ''
46
- clear_cols = ['得意先コード', '請求日', '請求番号', '件名', 'メモ']
47
- for col in clear_cols:
48
- if col in new_group.columns:
49
- new_group.iloc[1:, new_group.columns.get_loc(col)] = ''
50
- dfs.append(new_group)
51
-
52
- df_modified = pd.concat(dfs)
53
-
54
- # Save the modified dataframe to the output file
55
- output_file_path = "/content/processed.csv"
56
- df_modified.to_csv(output_file_path, index=False, encoding="MS932")
57
-
58
- return output_file_path
59
-
60
- # Webアプリを作成
61
- app = gr.Interface(fn=process_csv, inputs="file", outputs="file")
62
- # Webアプリを起動
63
- app.launch(debug=True)