4

While reading data from json to pandas, a multi criteria hotel ratings columns is read as shown below. I have 2 columns in my dataframe Ratings and ReviewID. Since I read the dataframe from a larger Json the Rating column has one entry for every reviewer, which is in the form:

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

My purpose is to divide the rating column into have 7 different columns, each having the respective criterion's value: `

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`

Anyone recommendations with the formatting, would be of great help ..

available dataframe Required dataframe

Ku91l
  • 99
  • 1
  • 6

1 Answers1

5

The below code worked for me `

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


   Service   Cleanliness     Overall
         0        5               5
         1        4               4`
Ku91l
  • 99
  • 1
  • 6