shZhang_HuaWeiMatebookD 1 сар өмнө
parent
commit
459d4913c0
5 өөрчлөгдсөн 21 нэмэгдсэн , 18 устгасан
  1. 3 3
      剖面容重.py
  2. 3 3
      剖面水稳.py
  3. 3 3
      容重匹配.py
  4. 4 4
      水稳匹配.py
  5. 8 5
      转码.py

+ 3 - 3
剖面容重.py

@@ -1,8 +1,8 @@
 import pandas as pd
 import numpy as np
-df_1 = pd.read_excel(r"D:\guozhong\泾县数据集20241118\泾县剖面数据统计20241118.xlsx")
+df_1 = pd.read_excel(r"D:\guozhong\19、定远县\19、定远县\定远县剖面数据统计20241222.xlsx",converters={'原样品编号': str})
 df_1
-df_2 = pd.read_excel(r"D:\guozhong\泾县数据集20241118\泾县容重汇总20241118.xlsx")
+df_2 = pd.read_excel(r"D:\guozhong\19、定远县\19、定远县\定远县土壤容重.xlsx",converters={'原样品编号': str})
 df_2
 # 确保列为字符串类型
 df_1["原样品编号"] = df_1["原样品编号"].astype(str)
@@ -27,4 +27,4 @@ merged_df = merged_df.drop(columns=["原样品编号前16位", "样品编号前1
 
 # 输出结果
 print(merged_df)
-merged_df.to_excel(r"泾县剖面容重.xlsx", index=False, engine="openpyxl")
+merged_df.to_excel(r"定远剖面容重.xlsx", index=False, engine="openpyxl")

+ 3 - 3
剖面水稳.py

@@ -1,9 +1,9 @@
 import pandas as pd
 import numpy as np
 
-df_1 = pd.read_excel(r"D:\guozhong\泾县数据集20241118\泾县剖面数据统计20241118.xlsx",converters={'容重样品编号': str})
+df_1 = pd.read_excel(r"D:\guozhong\19、定远县\19、定远县\定远县剖面数据统计20241222.xlsx",converters={'原样品编号': str})
 df_1
-df_2 = pd.read_excel(r"D:\guozhong\泾县数据集20241118\泾县水稳汇总20241110.xlsx")
+df_2 = pd.read_excel(r"D:\guozhong\19、定远县\19、定远县\定远县水稳清除后汇总20241222.xlsx",converters={'原样品编号': str})
 df_2
 # 确保列为字符串类型
 df_1["原样品编号"] = df_1["原样品编号"].astype(str)
@@ -33,4 +33,4 @@ merged_df = merged_df.drop(columns=["原样品编号前16位", "样品编号前1
 
 # 输出结果
 print(merged_df)
-merged_df.to_excel(r"泾县剖面水稳.xlsx", index=False, engine="openpyxl")
+merged_df.to_excel(r"定远剖面水稳.xlsx", index=False, engine="openpyxl")

+ 3 - 3
容重匹配.py

@@ -1,8 +1,8 @@
 import pandas as pd
 
 # 读取Excel文件
-df1 = pd.read_excel(r'D:\guozhong\来安县\来安县\9、来安县\来安县表层数据统计.xlsx', converters={'原样品编号': str})
-df2 = pd.read_excel(r'D:\guozhong\来安县\来安县\9、来安县\来安县土壤容重.xlsx')
+df1 = pd.read_excel(r'D:\guozhong\19、定远县\19、定远县\定远县表层数据统计20241222.xlsx', converters={'原样品编号': str})
+df2 = pd.read_excel(r'D:\guozhong\19、定远县\19、定远县\定远县土壤容重.xlsx')
 
 print(df1)
 # 确保 '原样品编号' 列是字符串类型
@@ -30,4 +30,4 @@ for id in df1['Processed ID']:
         empty_row = pd.Series([''] * len(df2.columns), index=df2.columns)
         result_df = pd.concat([result_df, empty_row.to_frame().T], ignore_index=True)
 
-result_df.to_excel('来安容重.xlsx', index=False)
+result_df.to_excel('定远表层容重.xlsx', index=False)

+ 4 - 4
水稳匹配.py

@@ -1,12 +1,12 @@
 import pandas as pd
 import numpy as np
-df_1 = pd.read_excel(r"D:\guozhong\来安县\来安县\9、来安县\来安县表层数据统计.xlsx")
+df_1 = pd.read_excel(r"D:\guozhong\19、定远县\19、定远县\定远县表层数据统计20241222.xlsx",converters={"原样品编号":str})
 df_1
-df_2 = pd.read_excel(r"D:\guozhong\来安县\来安县\9、来安县\来安县水稳数据.xlsx")
+df_2 = pd.read_excel(r"D:\guozhong\19、定远县\19、定远县\定远县水稳清除后汇总20241222.xlsx",converters={"原样品编号":str})
 df_2
 # 确保列为字符串类型
 df_1["原样品编号"] = df_1["原样品编号"].astype(str)
-df_2["样品编号"] = df_2["样品编号"].astype(str)
+df_2["样品编号"] = df_2["样品编号"].astype(str)
 
 # 提取前16位进行匹配
 df_1["原样品编号前16位"] = df_1["原样品编号"].str[:16]
@@ -26,4 +26,4 @@ merged_df = merged_df.drop(columns=["原样品编号前16位", "样品编号前1
 
 # 输出结果
 print(merged_df)
-merged_df.to_excel(r"来安水稳.xlsx", index=False, engine="openpyxl")
+merged_df.to_excel(r"定远表层水稳.xlsx", index=False, engine="openpyxl")

+ 8 - 5
转码.py

@@ -1,17 +1,20 @@
 import pandas as pd
 
 # 读取两个表
-table1 = pd.read_excel(r"D:\guozhong\泾县数据集20241118\泾县转码表.xlsx")  # 表1
-table2 = pd.read_excel(r"D:\guozhong\泾县数据集20241118\泾县水稳汇总20241110.xlsx")  # 表2
+table1 = pd.read_excel(r"D:\guozhong\19、定远县\19、定远县\定远县转码表.xlsx",converters={"样品编号":str})  # 表1
+table2 = pd.read_excel(r"D:\guozhong\19、定远县\19、定远县\定远县表层数据统计20241222.xlsx")  # 表2
 
 
 # 确保两表列数据类型一致,转换为字符串
-table1["转码后样品编号"] = table1["转码后样品编号"].astype(str)
-table1["样品编号"] = table1["样品编号"].astype(str)
+table1["转码后样品编号"] = table1["样品编号"].astype(str)
+table1["样品编号"] = table1["样品编号"].astype(str)
 table2["样品编号"] = table2["样品编号"].astype(str)
+print(table1)
+print(table2)
 
 # 提取表2的样品编号列
 sample_ids_table2 = table2["样品编号"].tolist()
+print(sample_ids_table2)
 
 # 创建一个列表,用于存储匹配结果
 matched_results = []
@@ -24,7 +27,7 @@ for sample_id in sample_ids_table2:
 
 # 将结果转为 DataFrame 并保存到 Excel 文件
 output_df = pd.DataFrame(matched_results, columns=["表2样品编号", "表1样品编号"])
-output_path = r"D:\guozhong\泾县剖面水稳转码.xlsx"
+output_path = r"D:\guozhong\定远表层转码.xlsx"
 output_df.to_excel(output_path, index=False)
 
 print(f"匹配完成!结果已保存到 {output_path}")