Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dividing json row data into multiple columns of pandas dataframe [duplicate]

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

like image 527
Ku91l Avatar asked Oct 31 '25 07:10

Ku91l


1 Answers

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`
like image 125
Ku91l Avatar answered Nov 02 '25 07:11

Ku91l



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!