json - 将json行数据划分为pandas数据框的多列
问题描述
从 json 读取数据到 pandas 时,读取多标准酒店评级列,如下所示。我的数据框 Ratings 和 ReviewID 中有 2 列。由于我从较大的 Json 中读取数据框,因此 Rating 列为每个审阅者提供了一个条目,其形式为:
`result.head()
Ratings ReviewID
0 {'Service': '5', 'Cleanliness': '5', 'Overall'... 12
1 {'Service': '4', 'Cleanliness': '4', 'Overall'... 54
2 {'Service': '5', 'Cleanliness': '5', 'Overall'... 48
3 {'Service': '5', 'Cleanliness': '5', 'Overall'... 90
4 {'Service': '5', 'Cleanliness': '5', 'Overall'... 75`
我的目的是将评级列分为 7 个不同的列,每个列都有各自的标准值:`
ReviewID Service Cleanliness Value Rooms Location Check-in Desk Overall
27 1 1 5 4 5 5 5 4
9 1 5 5 5 5 4 3 5
22 6 3 2 4 3 3 3 3`
任何具有格式的建议都会有很大帮助..
解决方案
下面的代码对我有用`
Rating = result['Ratings'].values.tolist()
rate = pd.DataFrame(Rating,columns =['Service', 'Cleanliness','Overall'])
Service Cleanliness Overall
0 5 5
1 4 4`
推荐阅读
- linux - 如果值不存在如何跳过空格并打印正确的行和列
- python - Pytest:我们是否有任何钩子来检查夹具是否被积极执行?
- javascript - javascript 对象:将逗号分隔的对象(数字)转换回数组列表
- python - 随机单击以保持会话活动 selenium python
- c# - 使用没有命名空间前缀的用户控件名称
- javascript - 是否有检查某人是否对消息做出反应的功能?(discord.js)
- java - 如何跳过 Maven 中的编译错误
- ios - 在 SwiftUI 中,如何删除卡在键盘顶部的视图
- javascript - 在reactjs中将我的json数组转换为我的json结构
- jenkins - jenkins 与 xray jira 的集成