首页 > 解决方案 > Python:无法循环遍历应用程序数据的电子表格以提取符合参数的信息

问题描述

我正在为我的研究生班做一个中期项目,使用我的工作必须处理的情况,即整理 CARES Act 租金援助申请。

我的目标是将满足某些参数的应用程序“发送”到两个不同的部门(在这种情况下,我计划进行 TXT 报告),其余的将被进一步过滤并分类为更多类别。

现在我将第一部分设置为许多嵌套的 if/elif 语句。我的问题是它只报告一个应用程序。我需要使用什么来让代码在整个列表中运行并在 TXT 文件或 shell 中全部报告回来?

到目前为止,我只研究了以 print 结尾的第一部分(listFEA),所以我还没有关注其他部分。

我也尝试过打开报告,但没有将其包含在此代码中,因为它不起作用。

    if caresValues [15] > "0":
        if caresValues [17] != "Yes":
            if caresValues [8] == "0":
                for i in caresValues:
                    listFEA.append(i)
                    print (listFEA)                    
        elif caresValues [18] != "Yes":
            if caresValues [8] != "0":
                print ("Refer to General Emergency Assistance.")
    if caresValues [15] == "0":
        print caresValues
                
else:
    print ("Refer to community provider.")```

标签: pythonloopsif-statement

解决方案


最初需要 For 子句来检查每个应用程序。

list_of_apps = ['a','b','c','d','e','f','g','h']
outcome = []

# You would need the for clause which will do the check for each application.
for i in range(0, len(list_of_apps))
    if ...
    elif...
    else..

# this would put your result into outcome df
outcome.append(result)

推荐阅读