相关疑难解决方法(0)

Pandas DataFrame到词典列表

我有以下DataFrame:

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'}]
Run Code Online (Sandbox Code Playgroud)

python dictionary list dataframe pandas

125
推荐指数
4
解决办法
6万
查看次数

标签 统计

dataframe ×1

dictionary ×1

list ×1

pandas ×1

python ×1