Python 如何分解dataframes.loc结果?

Python 如何分解dataframes.loc结果?,python,pandas,dataframe,flask,Python,Pandas,Dataframe,Flask,我试图将pandas dataframe.loc搜索的结果分解为各种变量。然后,我想将这些变量添加到一个对象中,并将该对象推送到一个结果数组中。我需要对所有匹配的行重复这些步骤 但是,我不知道如何正确地分解pandas dataframe.loc的结果 这是我的密码: # First I search through the sorted_csv and find all the rows # where First Name is "Cary". This works,

我试图将pandas dataframe.loc搜索的结果分解为各种变量。然后,我想将这些变量添加到一个对象中,并将该对象推送到一个结果数组中。我需要对所有匹配的行重复这些步骤

但是,我不知道如何正确地分解pandas dataframe.loc的结果

这是我的密码:

# First I search through the sorted_csv and find all the rows 
# where First Name is "Cary". This works, and returns all the matching rows.
foundResults = sorted_csv.loc[sorted_csv["First Name"] == "Cary"]
       
# Then I need to destructure each found row, create an object, 
# and push it to a results array
for row in foundResults:
    # Error here ** 
    idx, first_name, last_name, state, phonenumber = row

    # Create object
    row_to_search_match_dict = {
            "first_name": first_name,
            "last_name": last_name,
            "state": state,
            "phonenumber": phonenumber
    }

    # Push to results array
    results.append(row_to_search_match_dict)
**错误代码:
idx、名字、姓氏处的代码错误
。。。错误消息是
ValueError:要解压缩的值太多(预期为5个)


我已尝试删除
idx

行中的条目似乎太多,无法分配给它

它的值太多,空间太小。试着做

对于foundResults[[“idx”、“名”、“姓”、“州”、“电话号码”]]中的行:
具体选择行中的元素数