我有一個.csv文件,其中一列名爲Trigger
,另外兩列名爲void1
和void2
。將.csv文件中的值讀入列表字典
的數據是這樣的:
Trigger;void1;void
good;not good;not to good;
我想用這個數據來創建一個字典,看起來像這樣:
dictionary ={"good":["not good", "not to good"]}
我用下面的代碼開始:
df = pd.read_csv('dictionary.csv', sep =";")
for index, row in df.iterrows():
dictionary[row['trigger']] = row['void1']
哪個有效。但是,當我嘗試:
df = pd.read_csv('dictionary.csv', sep =";")
for index, row in df.iterrows():
dictionary[row['trigger']] = row['void1', 'void2']
它不起作用。任何想法如何我可以得到我期待的輸出?
'dictionary [row ['trigger']] = [row ['void1'],row ['void2']]''? –