ฉันมีแฟ้ม csv นั่นตอนที่โหลดดูเหมือนว่าเรื่องนี้
chicken, meat
veal, meat
rice, carbs
potato, carbs
carrot, veggies
mushroom, veggies
apples, fruits
ฉันอยากจะสร้างพจนานุกรมจากมันฉันกำลังใช้รหัส:
food = pd.read_csv('foods.csv', header=None, index_col=1, squeeze=False).to_dict()
เมื่อฉันพิมพ์ที่พจนานุกรมเดียวรายการแสดงเพื่อกันและกุญแจ แทนที่จะเป็นฉันคงเหมือนกับเพื่อให้แสดงแบบนี้
{'carbs':['potato','rice'],
'meat':['chicken','veal'],
'veggies':['mushroom','carrot'],
'fruits':['apples']}