Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +27 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
def merge_excel_tables(file_path1, file_path2):
|
5 |
+
df1 = pd.read_excel(file_path1.name, engine='openpyxl')
|
6 |
+
df2 = pd.read_excel(file_path2.name, engine='openpyxl')
|
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后缀
|
15 |
+
if new_col in column_mapping:
|
16 |
+
column_mapping[new_col] = new_col # 如果存在相同的列名,保持不变
|
17 |
+
merged_df.rename(columns={col: new_col}, inplace=True)
|
18 |
+
elif col.endswith('_y'):
|
19 |
+
new_col = col[:-2] # 去除_y后缀
|
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 |
+
# new_result = pd.DataFrame( merged_df)
|
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()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
pandas
|