123456789101112131415161718192021222324252627282930313233343536373839 |
- import pandas as pd
- table1 = pd.read_excel(r"D:\guozhong\庐江县\8、庐江县\剖面\庐江县剖面.xlsx")
- table2 = pd.read_excel(r"D:\guozhong\庐江县\8、庐江县\庐江县剖面数据统计20241124.xlsx")
- sample_ids_table2 = table2["样品编号"].tolist()
- sample_count = len(sample_ids_table2)
- result = []
- print("样品编号总数:", sample_count)
- for sample_id in sample_ids_table2:
-
- matched_rows = table1[table1["样品编号"] == sample_id]
-
- if not matched_rows.empty:
-
- first_matched_row = matched_rows.iloc[0]
- result.append((sample_id, first_matched_row.to_dict()))
- else:
-
- result.append((sample_id, {}))
- output_data = []
- for item in result:
- row_dict = {"样品编号": item[0], **item[1]}
- output_data.append(row_dict)
- output_df = pd.DataFrame(output_data)
- output_df.to_excel("庐江剖面地理信息.xlsx", index=False)
|