首页 > 解决方案 > 将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`

任何具有格式的建议都会有很大帮助..

可用数据框 所需数据框

标签: jsonpandasrecommender-systems

解决方案


下面的代码对我有用`

Rating = result['Ratings'].values.tolist()
 rate = pd.DataFrame(Rating,columns =['Service', 'Cleanliness','Overall'])


   Service   Cleanliness     Overall
         0        5               5
         1        4               4`

推荐阅读