Home > Blockchain >  How to extract data from a column with list of dict and backslash
How to extract data from a column with list of dict and backslash

Time:01-17

enter image description here Here is the first element of a dataframe

How can I for exemple get the number of different dict or item_id value for each dict ?

The problem is that is not a list of dict. If I try to get each element of this list, the output is just all element one by one not the 3 differents list.

CodePudding user response:

Try to convert your string as list with ast.literal_eval:

import ast

australian_user_reviews['reviews'] = australian_user_reviews['reviews'].map(ast.literal_eval)

Now you can use str.len() to get the length of each list:

australian_user_reviews['count'] = australian_user_reviews['reviews'].str.len()
  • Related