I have this dataframe. How I got this dataframe was due to using .to_dict()
. It manages to split the initial dictionary into individual columns on key:value pairs. However some keys has a dictionary like value. For instance like the Ambience column here.
I believe the initial dictionary is something like this
attribute = {
"AcceptsInsurance": "null",
"AgesAllowed": "null',
"Ambience": {
'touristy': False,
'hipster': False,
'romantic': False,
'divey': False,
'intimate': False
}
} ...
The column value are in a dictionary like object but are not dictionary. The column are in object type.
+---------------+--------------------------------------------------------------------------------------------+
| business_id| Ambience|
+---------------+--------------------------------------------------------------------------------------------+
|6iYb2HFDywm3zjw|{'touristy': False, 'hipster': False, 'romantic': False, 'divey': False, 'intimate': False} |
|drRPZA0oiIYSmqs|{'romantic': False, 'intimate': False, 'classy': False, False, 'casual': True} |
+---------------+-------------+------------------------------------------------------------------------------+
I would like to hence further split it and create new column for each of the element of the key:value pair. So something like this,
+-----------------+------------------+-------------------+
| business_id| Ambience_touristy| Ambience_romantic|
+-----------------+------------------+-------------------+
| 6iYb2HFDywm3zjw| False| False|
| drRPZA0oiIYSmqs| Null| False|
+-----------------+------------------+-------------------+
How do I go about doing this? I am new to this and would appreciate any help.