python - 如何在 Python Pandas 中将多行更改为单行
问题描述
我的数据框看起来像:
item_id item_name item_desc rating item_type price
0 it1 laptop 6.0 asus 50000.0
1 it1 laptop 7.0 acer 30000.0
2 it1 laptop 3.0 hp 20000.0
3 it2 smartphone 6.0 iphone 600000.0
4 it2 smartphone 5.0 samsung 750000.0
5 it1 laptop 4.0 dell 10000.0
6 it3 radio Best radio 8.0 tech 30000.0
7 it3 radio Best radio 9.0 tech 30000.0
我想改变它们的样子:
item_id item_name item_desc average_rating item_type \
0 it1 laptop 4.0 [asus, acer, hp, dell]
1 it2 smartphone 5.5 [iphone, samsung]
2 it3 radio Best radio 8.5 [tech]
price
0 [50000, 30000, 20000, 10000]
1 [600000, 750000]
2 [30000]
从上面,我想将列 rating 中的多个数据更改为 average_rating,将 item_type 和 price 中的多个数据转换为列表。
你能帮我看看python pandas中的脚本程序怎么样?
解决方案
推荐阅读
- javascript - MongoDB:如何避免集合中的名称双倍
- ios - 如何在没有 RPSystemBroadcastPickerView 的情况下以编程方式停止 ReplayKit 2 系统广播
- python - 展平嵌套字典并将其转换为列
- plugins - 在 eclipse 2020-03 中下载 clearcase 插件
- mysql - 如何从多个表中选择条目,其中一些带有计数?
- r - 如何将数据框中的部分重复项设置为空
- ios - ios azure 管道构建失败并出现错误在存档中找不到团队 ID
- python - Python/Excel/SQL 列日期到爆炸行
- symfony - symfony5/Mercure : 如何解决我无法连接到我的 Mercure 集线器的问题
- javascript - Kendo Ui TabStrip 左右按钮禁用即时隐藏