I have a JSON list that I normalized with the following code:
json_nor = pd.json_normalize(data, max_level=1)
pd.set_option('display.max_colwidth', None)
#view json_nor
json_nor
This is the result when viewing the json_nor
I then cleaned up this data using the following code:
df = json_nor.explode('APIResponse.data').reset_index(drop=True)
# Normalize the 'APIResponse.data' column into a DataFrame
data_df = pd.json_normalize(df['APIResponse.data'])
# Drop the 'APIResponse.data' column from the original DataFrame
df = df.drop('APIResponse.data', axis=1)
# Concatenate the original DataFrame and the normalized DataFrame along the columns axis
df = pd.concat([df, data_df], axis=1)
#show the datafram
df
This is the output of the df
What would be the best approach to change this so that there is one row per address, and that there is a separate column for each Name, Phone, and Email associated with that address?
I was thinking of using the pandas .split() method, but it is impossible to know how many columns will be the final output for each address, as each address has a different number of names, phones, and emails associated with it. I was also thinking of using regex, but could not figure out the right way to do it.