I have a data frame that looks like this
account_id result
0 588930 {"symbol": "MSFT", "balance": 0.00...
and when I print a single cell value of the result column I get the following, which seems to be a string of dicts:
'{"symbol": "MSFT", "balance": 0.00, "transactionId": 10496491},{"symbol": "AAPL", "balance": 300.12, "transactionId": 10509620},{"symbol": "TSLA", "balance": 40.4, "transactionId": 10632589}'
Other users may have different symbol assets.
I want to access the content in result
as dictionaries in order to expand the content into multiple columns where the column names are the symbols
(ex: MSFT, TSLA...) and the values are the balance
numbers.
I haven't been able to transform the string into dictionaries to be able to access the contents.
Thanks!
UPDATE
I tried the following
def string_to_dict(dict_string):
# Convert to proper json format
dict_string = dict_string.replace("'", '"').replace('u"', '"')
return json.loads(dict_string)
df.result = f.result.apply(string_to_dict)
But I get the following error
JSONDecodeError: Extra data: line 1 column 93 (char 92)
which I believe means that json.loads cannot decode multiple dictionaries at the same time As described here