Home > Blockchain >  Extracting a value from a dictionary within a list
Extracting a value from a dictionary within a list

Time:09-15

I have a DF column that is a dictionary within a list. I want to create a new column with the 'value' from value in the dictionary i.e. 'IT-Sourced Changes 2022', but with the below, I'm getting NaN values.

import pandas as pd

data = [10,[{'self': 'https://elia.atlassian.net/rest/api/3/customFieldOption/10200', 'value': 'IT-Sourced Changes 2022', 'id': '10200'}],30]
df = pd.DataFrame(data, columns=['Data'])
df['new_col']= df['Data'].str['value']
df.head(3)

CodePudding user response:

As you have a list of a dictionary, you need to explode it first:

df.Data.explode().str['value']
  • Related