将json行数据分成pandas dataframe的多列

Ku9*_*91l 4 json recommendation-engine pandas

从 json 读取数据到 pandas 时,会读取多条件酒店评级列,如下所示。我的数据框评级和 ReviewID 中有 2 列。由于我从较大的 Json 中读取数据帧,因此评级列为每个审阅者都有一个条目,其形式为:

`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`
Run Code Online (Sandbox Code Playgroud)

我的目的是将评级列分为 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`
Run Code Online (Sandbox Code Playgroud)

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

可用数据框 所需数据框

Ku9*_*91l 5

下面的代码对我有用`

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


   Service   Cleanliness     Overall
         0        5               5
         1        4               4`
Run Code Online (Sandbox Code Playgroud)