Home > Net >  extract values from nested dictionary in pandas dataframe column
extract values from nested dictionary in pandas dataframe column

Time:09-01

I have pandas column, one sample value looks like this

 colName1 {'key1': {'key2': {'ke3': {'label': '3 minutes, 16 seconds'}}, 'simpleText': '3:16'}, 'style': 'DEFAULT'}

tried this but din't work.

df1['XYZ'] = df1['colName1'].apply(lambda x: x['key1']['key2']['simpleText'])

How can I retrieve the value of 'simpleText' which equals to 3:16

CodePudding user response:

Use

x['key1']['simpleText']

key2 is redundant.

CodePudding user response:

Let's try

df1['XYZ'] = df1['colName1'].str['key1'].str['simpleText']

CodePudding user response:

#Try this:

val['XYZ'] = val['key1']['simpleText']
print(val['XYZ'])

#output: 3:16

  • Related