【问题标题】:Dividing json row data into multiple columns of pandas dataframe [duplicate]将json行数据划分为pandas数据框的多列[重复]
【发布时间】:2020-05-17 11:22:11
【问题描述】:

在从 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`

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

available dataframe Required dataframe

【问题讨论】:

    标签: json pandas recommender-systems


    【解决方案1】:

    以下代码对我有用 `

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

    【讨论】:

      猜你喜欢
      • 2019-07-25
      • 2017-10-10
      • 1970-01-01
      • 2019-06-18
      • 1970-01-01
      • 2018-03-26
      • 2021-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多