Skip to content
Advertisement

Parse pandas series with a list of dicts into new columns

I have a pandas series containing a list of dictionaries. I’d like to parse the contents of the dicts with some condition and store the results into new columns.

Here’s some data to work with:

JavaScript

I’d like to parse the contents of each dictionary with some conditional logic. Check for each dicts in the list and name columns as keys br and ba. Get the value of r key as assign as column value. If key is not found, br in this example, assign 0 as the value. Expected output:

JavaScript

Advertisement

Answer

Try:

JavaScript

Prints:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement