I have a dataframe where some columns are formatted this way:
example value of ColX:
{variable1={key:value,key2:value2.....}, variable2={key3:value3,key4:value4.....}}
Let's say I want to access value2 and value4. How can I address them using Python?
My desired result is to make a column key2 with value2's and column key4 with all the value4's
Sorry. I could not google the name of this data structure. It's something like a list of dictionary definitions packed into strings.
CodePudding user response:
The data structure is simply a nested dict. Try some of the answers given here: Safe method to get value of nested dictionary. Dict methods can be concatenated, so you can do:
dictionary.get(keyname, value).get(keyname, value)
CodePudding user response:
You are using dictionnaries of dictionnaries (I think). In order to get to value 2 you need to get first to variable 1, and then to key2 so you can do this, if your dictionnary is stored in ColX :
ColX.get(variable1).get(key2)
By the way are you sure of the syntax of ColX ? Isn't it :
{variable1:{key:value,key2:value2.....}, variable2:{key3:value3,key4:value4.....}}