elia_Werner
elia_Werner

Reputation: 19

Extracting a value from a dictionary within a list

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)

Upvotes: 1

Views: 38

Answers (1)

Nuri Taş
Nuri Taş

Reputation: 3845

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

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

Upvotes: 3

Related Questions