You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python csv.reader筛选未开票功能性金额≥$10000的供应商

解决CSV供应商未开票金额筛选问题

代码实现与说明

基于你提供的代码框架,我们需要在遍历CSV时追踪当前供应商ID,提取并转换未开票金额进行筛选,最终输出符合要求的供应商信息:

companyList = {'1000000': 'Vendor1', ...}

current_vendor_id = None

with open('Vendor Report.csv', mode='r', encoding='latin1') as file:
    csvreader = csv.reader(file)
    for row in csvreader:
        row_str = ' '.join(row)
        
        # 识别并记录当前供应商ID(适配CSV中ID出现的逻辑,可根据实际结构调整)
        for item in row:
            if item in companyList:
                current_vendor_id = item
                break
        
        # 处理未开票金额行
        if 'Functional Amount Not Invoiced:' in row_str:
            # 提取金额文本
            amount_text = row_str.split('Functional Amount Not Invoiced: ')[1].strip()
            # 转换为可比较的数值
            amount_num = float(amount_text.replace('$', '').replace(',', ''))
            
            # 筛选金额≥$10,000.00的供应商
            if amount_num >= 10000.00:
                vendor_name = companyList.get(current_vendor_id, '未知供应商')
                # 按指定格式输出
                print(f"{current_vendor_id} {vendor_name} {amount_text}")

关键逻辑说明

  1. 供应商ID追踪:遍历每行时检查元素是否存在于companyList的键集合中,确定当前处理的供应商;若CSV中供应商ID有明确标识(如行开头为Vendor ID:),可替换为更精准的匹配逻辑,比如:
    if row_str.startswith('Vendor ID:'):
        current_vendor_id = row_str.split('Vendor ID:')[1].strip()
    
  2. 金额转换与筛选:将带$和千分位逗号的金额文本转换为浮点数,完成数值比较;筛选达标后,从companyList中匹配供应商名称并按格式输出。

内容的提问来源于stack exchange,提问作者user19891327

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 00:40:19