Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
def merge_excel_tables(file_path1, file_path2):
|
5 |
-
df1 =
|
6 |
-
df2 =
|
7 |
merged_df = df1.merge(df2, left_on=list(df1.columns)[0], right_on=list(df2.columns)[0], how='left')
|
8 |
column_mapping = {}
|
9 |
for col in df1.columns:
|
10 |
column_mapping[col] = col
|
11 |
-
|
12 |
for col in merged_df.columns:
|
13 |
if col.endswith('_x'):
|
14 |
new_col = col[:-2] # 去除_x后缀
|
@@ -20,8 +27,9 @@ def merge_excel_tables(file_path1, file_path2):
|
|
20 |
merged_df.rename(columns={col: new_col}, inplace=True)
|
21 |
merged_df = merged_df.dropna(axis=1, how='all')
|
22 |
merged_df = merged_df[list(df1.columns)]
|
23 |
-
|
24 |
return merged_df
|
25 |
|
|
|
26 |
iface = gr.Interface(fn=merge_excel_tables, inputs=["file", "file"], outputs=gr.outputs.Dataframe(type='pandas'), title="强哥的Excel Processor", description="根据表格一的第一列,寻找表格二对应第一列的行数据,把表格二中与表格一相同标签数据填入表格一")
|
27 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
|
4 |
+
import gradio as gr
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
|
8 |
+
def process_excel(file):
|
9 |
+
df = pd.read_excel(file.name, engine='openpyxl')
|
10 |
+
return df
|
11 |
+
|
12 |
def merge_excel_tables(file_path1, file_path2):
|
13 |
+
df1 = process_excel(file_path1)
|
14 |
+
df2 = process_excel(file_path2)
|
15 |
merged_df = df1.merge(df2, left_on=list(df1.columns)[0], right_on=list(df2.columns)[0], how='left')
|
16 |
column_mapping = {}
|
17 |
for col in df1.columns:
|
18 |
column_mapping[col] = col
|
|
|
19 |
for col in merged_df.columns:
|
20 |
if col.endswith('_x'):
|
21 |
new_col = col[:-2] # 去除_x后缀
|
|
|
27 |
merged_df.rename(columns={col: new_col}, inplace=True)
|
28 |
merged_df = merged_df.dropna(axis=1, how='all')
|
29 |
merged_df = merged_df[list(df1.columns)]
|
30 |
+
merged_df.to_excel(output_file, index=False)
|
31 |
return merged_df
|
32 |
|
33 |
+
|
34 |
iface = gr.Interface(fn=merge_excel_tables, inputs=["file", "file"], outputs=gr.outputs.Dataframe(type='pandas'), title="强哥的Excel Processor", description="根据表格一的第一列,寻找表格二对应第一列的行数据,把表格二中与表格一相同标签数据填入表格一")
|
35 |
iface.launch()
|