Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading