我有这样的输入 Dataframe 。我想把price和qty列分组到字典中,如下所示。
-------------------------------------------------------------------------------------
| item_name | price_1 | qty_1 | price_2 | qty_2 | price_3 | qty_3 | url |
-------------------------------------------------------------------------------------
| Samsung Z | 10000 | 5 | 9000 | 10 | 7000 | 20 | amazon.com |
| Moto G4 | 12000 | 10 | 10000 | 20 | 6000 | 50 | ebay.com |
| Mi 4i | 15000 | 8 | 12000 | 20 | 10000 | 25 | deals.com |
| Moto G3 | 20000 | 5 | 18000 | 12 | 15000 | 30 | ebay.com |
--------------------------------------------------------------------------------------
- 输出:**
---------------------------------------------------------------------------------------------------------------------------------------
| item_name | price_range | url |
---------------------------------------------------------------------------------------------------------------------------------------
| Samsung Z | [{price:10000,qty:5, comments:""},{price:9000,qty:10, comments:""},{price:7000,qty:20, comments:""}] | amazon.com |
| Moto G4 | [{price:12000,qty:10, comments:""},{price:10000,qty:20, comments:""},{price:6000,qty:50, comments:""}] | ebay.com |
| Mi 4i | [{price:15000,qty:8, comments:""},{price:12000,qty:20, comments:""},{price:10000,qty:25, comments:""}] | deals.com |
| Moto G3 | [{price:20000,qty:5, comments:""},{price:18000,qty:12, comments:""},{price:15000,qty:30, comments:""}] | ebay.com |
---------------------------------------------------------------------------------------------------------------------------------------
1条答案
按热度按时间e0bqpujr1#
迭代列以找到每个价格、数量对,并使用create_map()从它们创建Map列。
然后使用array()将所有Map列收集为数组。
输出: