我有以下數據框:熊貓數據框中列出字典
customer item1 item2 item3 1 apple milk tomato 2 water orange potato 3 juice mango chips
,我想將它轉化爲每行
rows = [{'customer': 1, 'item1': 'apple', 'item2': 'milk', 'item3': 'tomato'},
{'customer': 2, 'item1': 'water', 'item2': 'orange', 'item3': 'potato'},
{'customer': 3, 'item1': 'juice', 'item2': 'mango', 'item3': 'chips'}]
歡迎來到Stack Overflow!我將代碼示例縮進4個空格,以便正確渲染 - 請參閱編輯幫助以獲取有關格式化的更多信息。 – ByteHamster