這里是業余到中級 Python 程式員。
我有一個 Excel .csv,我正試圖從中提取一些特定資料。我已經設法將原始資料提取到 Python 中的字典串列中。資料由大約十幾個不同的鍵(Excel 表中的列)組成,但我需要的只是兩個鍵中的資料。
我想根據第二個鍵中的對應值是否滿足某些要求來提取一個鍵的值。這兩個鍵是“UnitId”和“A5000 總體滿意度”(這是與客戶服務相關的資料),我想提取對應 A5000 值為 5 的每個 UnitId 值。
問題是到目前為止,我嘗試過的所有功能都無法提取任何東西,并且總是產生一個空字典或串列(取決于我嘗試的方法)。我最近的函式嘗試給了我一些進步,但結果并不包含我想要的所有資料。
我試圖簡單地提取 A5000 值為 5 的每個字典,希望一旦我將串列縮小到我需要的字典,就可以從那里提取 UnitId。但是,它沒有給我所有 A5000 值為 5 的字典,而是給了我一個A5000 值為 5 的單個字典結果的所有鍵。
這是我最近嘗試的代碼:
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)
這是一個指向compiled_data示例的pastebin鏈接供參考(直接在這里發布太長了,對于免費的pastebin用戶來說,完整的東西太大了):
這是我使用現有代碼得到的結果:
{
"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"
}
最終,我的問題是:如何提取對應 A5000 值為 5 的所有UnitId 值?
uj5u.com熱心網友回復:
我不確定我是否理解你想要做什么。但是此腳本將 A5000 為 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)
print(result)
重新閱讀問題后,這是一個將 UnitId 放入 A5000 為 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)
在這里,它是一個襯里:
result = [row['UnitId'] for row in data if row['A5000 Overall satisfaction'] == '5']
uj5u.com熱心網友回復:
您的問題是您在需要串列的地方使用字典。all_5_ratings.update(dict)覆寫您之前的任何條目。您可以使用串列,然后像您第一次讀入資料時那樣“追加”而不是“更新”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/413676.html
標籤:
下一篇:基本讀取CSV檔案問題
