快速在文件夹中搜寻报价的程序的思路

2022.4.25更新:

实现在文件夹中搜索相应字符串并打印的实际功能,后期还需要新建一个数据库总文件夹,把excel报价和带定额的工程项目清单报价分放在不同文件夹中。

import pandas as pd
import os
import glob

# Find all the excel files in the current folder
files = glob.glob('C:\\Users\\PAN\Desktop\\fo1\\*.xlsx')

# Create an empty list to store the DataFrames
dfs = []
search_string = '光束'
# Loop through the files and read each one into a DataFrame
for file in files:
    df = pd.read_excel(file)
    result = df[df.applymap(lambda x: search_string in str(x)).any(axis=1)]
    # 获取文件名并将其添加到 DataFrame 的新列中
    filename = os.path.basename(file)
    result = result.assign(file_name=filename)
    print(result)
    dfs.append(result)

file_path2 = 'C:\\Users\\PAN\Desktop\\fo1\\output.xlsx' # double backslashes are used to escape the single backslashes in Windows file paths
sheet_name = 'Sheet1'
combined_df = pd.concat(dfs)
combined_df.to_excel(file_path2, sheet_name=sheet_name, index=False)

——————————————————————————————————

所有报价文件统一格式,这样可以按列搜索项目名称,按行输出信息。

造价文件也可按此进行组织,用带套定额的版本统一输出,这样未来想查一查某个清单是怎么套定额(组价)的,可以直接python检索。

所有价格材料,只要统一格式的表格,都可以快速搜索价格和相关信息。

把某一类报价文件放在一个文件夹中,这样可以用Python进行检索:

import pandas as pd
import glob

# Find all the excel files in the current folder
files = glob.glob('*.xlsx')

# Create an empty list to store the DataFrames
dfs = []

# Loop through the files and read each one into a DataFrame
for file in files:
    df = pd.read_excel(file)
    dfs.append(df)

# Concatenate all the DataFrames into one
df = pd.concat(dfs)

# Display the result
print(df)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值