Following my question on Convert Dataframe to Nested Dictionary in Python, I have been trying to convert a Pandas dataframe into a nested dictionary.
Current challenge is merging multiple dictionaries inside a np.ndarray into one.
My current output
dklisarray([{0.7863340563991272: 0.0002639915522703274}, {0.7863340563991272: 0.0006863780359028511}], dtype=object)Which when checked for
typeresultsnumpy.ndarray.I need to get
dklto be{0.7863340563991272: 0.0002639915522703274, 0.7863340563991272: 0.0006863780359028511}
I am failing to get the desired results. I tried to turn dkl into a l1 = list(dkl), resulting in:
[{0.7863340563991272: 0.0002639915522703274},
{0.7863340563991272: 0.0006863780359028511}]
I am now able to get the two elements of the list above which are it1 = {0.7863340563991272: 0.0002639915522703274} and it2 = {0.7863340563991272: 0.0006863780359028511}, which I am trying to merge into one dictionary. I tried:
dict(it1.items() + it2.items())
resulting in:
TypeError Traceback (most recent call last)
<ipython-input-150-4422fd31b345> in <module>
----> 1 dict(it1.items() + it2.items())
TypeError: unsupported operand type(s) for +: 'dict_items' and 'dict_items'
In short, I need to get from 1 to 2.
Update: Ref to mention in comments that this shape of output is not possible in dict, I am tyring to understand how this comes about: 
Reason being that I have a dataset I need to replicate that is structured as shown above in my desired output, and if not possible with dict, I have no idea how it's been created...