I'm trying to find a way to split (flatten) JSON row data into multiple columns in pandas.
I have a dataframe which looks like the following:
Current Dataframe
This is an example of what a row looks like:
Row example
I'm able to use the json_normalize function on a single row to achieve the following: (It's just shortened as an example)
Code Example
Table
However, when trying to apply the normalize function to the whole dataframe, I get 'str' object has no attribute 'values'
Are there any suggestions for how to go about doing this? Thanks
I apologise for the use of images, but I kept getting a message saying code is not formatted properly
If it's a flat json then you can try :-
new_df = pd.DataFrame(df['tickers'].tolist())
The Dataframe constructor takes in a list of dictionary objects and turns the key into columns as default orientation, this is the simplest way if your data is standardized and doesn't have a complex nested structure.
all_data_jsons = df['tickers'].to_list()
df = pd.DataFrame(all_data_jsons)
Maybe you can try this once
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With