是否有可能(並且更重要的是,實用)將下面的代碼編寫爲字典理解? 我在這裏創建一個字典,然後檢查「空白」值(用' - '表示)並用另一個字符串值替換它。 test_dict = dict(zip(list_one,list_two))
for k,v in test_dict.items():
if v == '-':
test_dict[k] = 'missing'
我試圖創建一個字典從數據幀(DF)的兩列 mydict={x :y for x in df['Names'] for y in df['Births']}
但所有的值是(在列的最後一個值)一樣! {'Bob': 973, 'Jessica': 973, 'John': 973, 'Mary': 973, 'Mel': 973}
我檢查了列,它有許多其他值,我做錯了什麼?