Pandas提取Excel中唯一值的最后数值保存
import pandas as pd
# 假设数据保存在Excel文件中,加载数据
df = pd.read_excel(r'C:\\Users\\Administrator\\Desktop\\物料收发明细表_2024011709475312_230690_part1.xlsx')
# 根据唯一值取最后出现的数值
df['Last_Value'] = df.groupby('唯一值')['(结存)数量(库存)'].transform('last')
# 将结果保存到新的Excel文件
df.to_excel('output_excel_file.xlsx', index=False)