import pandas as pd

def search_equipment_info(filepath, keyword): # 读取原始数据 data = pd.read_excel(filepath)

# 查找匹配的数据
result = data[data['设备编号'].str.contains(keyword)]

# 输出查询结果
print(result)

# 将查询结果保存到新的 Excel 中
with pd.ExcelWriter('D:/WorkSapce/查询结果.xlsx', engine='openpyxl', mode='a', if_sheet_exists='overlay') as writer:
    result.to_excel(writer, sheet_name='Sheet1', index=False, header=False)

# 返回查询结果
return result
Python Pandas: 使用关键字搜索设备信息并保存结果

原文地址: https://www.cveoy.top/t/topic/lT3R 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录