Search code examples
pythoncsvdictionarydata-extractionkey-value-coding

How do I filter a group of dictionaries so that I can extract values from one key based on whether *another* key meets certain conditions?


Amateur-to-intermediate Python programmer here.

I've got an Excel .csv that I'm attempting to extract some specific data from. I've already managed to extract the raw data into a list of dictionaries in Python. The data consists of about a dozen different keys (columns in the Excel sheet), but what I need involves the data in only two keys.

I want to extract the values of one key based on whether corresponding values in the second key meet certain requirements. The two keys are "UnitId" and "A5000 Overall satisfaction" (this is customer service related data), and I want to extract every UnitId value whose corresponding A5000 value is 5.

The problem is up until now, none of the functions I've tried for doing this manage to extract anything, and always yielded an empty dictionary or list (depending on the method I tried). My most recent function attempt gave me some progress, but the results don't contain all the data I desired.

I tried to simply extract every dictionary with an A5000 value of 5, hoping to work out extracting the UnitIds from there once I had narrowed down the list to the dictionaries I needed. But, instead of giving me all dictionaries with A5000 values of 5, it gave me all the keys of a single dictionary result whose A5000 value was 5.

Here's the code I have from this most recent attempt:

import csv

compiled_data = []
all_5_ratings = dict()
with open("C:\%%%%%%%%%%%\CW test file.csv") as CW_test_file:
#Here is the code I used to display the raw data in the console
    CWtest_dict = csv.DictReader(CW_test_file)
    for row in CWtest_dict:
        compiled_data.append(row)
    print(compiled_data)
    print("################################################")
#Here is my most recent attempted function to extract the desired data:
    for dict in compiled_data:
        for key, value in dict.items():
            if key == "A5000 Overall satisfaction" and value == "5":
                all_5_ratings.update(dict)
            else:
                pass
    print(all_5_ratings)
    #Below is a failed previous attempt
    all_fives = [x for x in compiled_data if x["A5000 Overall satisfaction"] >= "5"]
    print(all_fives)

Here is a pastebin link to a sample of compiled_data for reference (It's way too long to post here directly and the full thing is too big for free pastebin users):

And here is the result I get with my existing code:

{
    "VisitDate": "10/28/2021 21:58",
    "UnitId": "2",
    "A4000 Type of visit": "2",
    "A5000 Overall satisfaction": "5",
    "A6000 Likelihood to return": "5",
    "A7000 Likelihood to recommend": "5",
    "A8000 Value for Price": "5",
    "A9000 Friendliness of host/hostess": "5",
    "A10000 Wait time to be seated": "5",
    "A11000 Friendliness of server": "4",
    "A12000 Wait time for drinks": "5",
    "A13000 Wait time for food": "5",
    "A14000 Server's menu knowledge": "5"
}

Ultimately, my question is: How do I extract all UnitId values whose corresponding A5000 values are 5?


Solution

  • I am not sure if I understood what you wanted to do. but this script puts all of the reviews where A5000 is 5 in a result array:

    data = [{'VisitDate': '10/11/2021 11:26', 'UnitId': '23', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '2', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 11:27', 'UnitId': '14', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '3', 'A8000 Value for Price': '3', 'A9000 Friendliness of host/hostess': '3', 'A10000 Wait time to be seated': '2', 'A11000 Friendliness of server': '2', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 11:38', 'UnitId': '22', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 11:52', 'UnitId': '11', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 12:02', 'UnitId': '14', 'A4000 Type of visit': '1', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 12:09', 'UnitId': '18', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 12:11', 'UnitId': '23', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 12:12', 'UnitId': '23', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '3', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 12:17', 'UnitId': '14', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 12:27', 'UnitId': '23', 'A4000 Type of visit': '1', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '3', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '3', 'A9000 Friendliness of host/hostess': '3', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '2', 'A12000 Wait time for drinks': '3', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:31', 'UnitId': '1', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:34', 'UnitId': '1', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:39', 'UnitId': '18', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 12:41', 'UnitId': '11', 'A4000 Type of visit': '1', 'A5000 Overall satisfaction': '3', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:44', 'UnitId': '17', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 12:49', 'UnitId': '2', 'A4000 Type of visit': '1', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 12:49', 'UnitId': '17', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '3', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '3', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:54', 'UnitId': '17', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:59', 'UnitId': '18', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 13:00', 'UnitId': '18', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 13:19', 'UnitId': '1', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 13:23', 'UnitId': '14', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '3', 'A11000 Friendliness of server': '3', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '3', "A14000 Server's menu knowledge": '1'}, {'VisitDate': '10/11/2021 13:36', 'UnitId': '2', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '3', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '2', 'A8000 Value for Price': '3', 'A9000 Friendliness of host/hostess': '3', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '3', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 13:37', 'UnitId': '18', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 13:38', 'UnitId': '2', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 13:41', 'UnitId': '16', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '3', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '3', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '2'}, {'VisitDate': '10/11/2021 13:45', 'UnitId': '21', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 13:55', 'UnitId': '16', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '3', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '3', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '3', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 14:07', 'UnitId': '23', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '3', 'A11000 Friendliness of server': '3', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}]
    result = []
    for row in data:
        if row['A5000 Overall satisfaction'] == '5':
            result.append(row)
    
    print(result)
    

    After re-reading the question, here is a version that puts the UnitId in an array where A5000 is 5

    data = [{'VisitDate': '10/11/2021 11:26', 'UnitId': '23', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '2', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 11:27', 'UnitId': '14', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '3', 'A8000 Value for Price': '3', 'A9000 Friendliness of host/hostess': '3', 'A10000 Wait time to be seated': '2', 'A11000 Friendliness of server': '2', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 11:38', 'UnitId': '22', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 11:52', 'UnitId': '11', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 12:02', 'UnitId': '14', 'A4000 Type of visit': '1', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 12:09', 'UnitId': '18', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 12:11', 'UnitId': '23', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 12:12', 'UnitId': '23', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '3', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 12:17', 'UnitId': '14', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 12:27', 'UnitId': '23', 'A4000 Type of visit': '1', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '3', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '3', 'A9000 Friendliness of host/hostess': '3', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '2', 'A12000 Wait time for drinks': '3', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:31', 'UnitId': '1', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:34', 'UnitId': '1', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:39', 'UnitId': '18', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 12:41', 'UnitId': '11', 'A4000 Type of visit': '1', 'A5000 Overall satisfaction': '3', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:44', 'UnitId': '17', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 12:49', 'UnitId': '2', 'A4000 Type of visit': '1', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 12:49', 'UnitId': '17', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '3', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '3', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:54', 'UnitId': '17', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}, {'VisitDate': '10/11/2021 12:59', 'UnitId': '18', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 13:00', 'UnitId': '18', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 13:19', 'UnitId': '1', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 13:23', 'UnitId': '14', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '3', 'A11000 Friendliness of server': '3', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '3', "A14000 Server's menu knowledge": '1'}, {'VisitDate': '10/11/2021 13:36', 'UnitId': '2', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '3', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '2', 'A8000 Value for Price': '3', 'A9000 Friendliness of host/hostess': '3', 'A10000 Wait time to be seated': '4', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '3', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 13:37', 'UnitId': '18', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 13:38', 'UnitId': '2', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 13:41', 'UnitId': '16', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '3', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '3', 'A11000 Friendliness of server': '4', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '2'}, {'VisitDate': '10/11/2021 13:45', 'UnitId': '21', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '5', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '5', 'A8000 Value for Price': '5', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '5', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '4'}, {'VisitDate': '10/11/2021 13:55', 'UnitId': '16', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '3', 'A6000 Likelihood to return': '5', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '3', 'A9000 Friendliness of host/hostess': '5', 'A10000 Wait time to be seated': '5', 'A11000 Friendliness of server': '5', 'A12000 Wait time for drinks': '3', 'A13000 Wait time for food': '5', "A14000 Server's menu knowledge": '5'}, {'VisitDate': '10/11/2021 14:07', 'UnitId': '23', 'A4000 Type of visit': '2', 'A5000 Overall satisfaction': '4', 'A6000 Likelihood to return': '4', 'A7000 Likelihood to recommend': '4', 'A8000 Value for Price': '4', 'A9000 Friendliness of host/hostess': '4', 'A10000 Wait time to be seated': '3', 'A11000 Friendliness of server': '3', 'A12000 Wait time for drinks': '4', 'A13000 Wait time for food': '4', "A14000 Server's menu knowledge": '3'}]
    result = []
    for row in data:
        if row['A5000 Overall satisfaction'] == '5':
            result.append(row["UnitId"])
    
    print(result)
    

    And here it is as a one liner:

    result = [row['UnitId'] for row in data if row['A5000 Overall satisfaction'] == '5']