0

Grateful for your help. I have data in JSON format within a dataframe. I'm trying to extract into new columns and append to the existing dataframe. Here's what my dataframe looks like:

Company Attribution
Papa John's Papa John's JSON data
KFC JSON data

Here's what the JSON data looks like:

[{'domain':'papajohns.com','country':'USA'},{'domain':'papajohns.co.uk,'country':'UK}] [{'domain':'kfc.com','country':'USA'},{'domain':'kfc.co.uk,'country':'UK}]

And the results should be:

Company domain country
Papa John's papajohns USA
Papa John's papajohns UK UK
KFC kfc USA
KFC kfc UK UK

The closest I've got to this is:

df_results = json_normalize(df1.to_dict('list'), ['Attribution'].unstack().apply(pd.Series)

But this does not append the Attribution columns to the Company columns. It does not seem to hit all rows, even when I've removed empty rows.

Other similar answers don't create new columns, based on the fields within the JSON.

Simnicjon
  • 105
  • 1
  • 11
  • I've voted to re-open. But please check if the duplicates help and show how far you get. Your "attempt" even has a syntax error. – Joooeey Apr 16 '23 at 16:56

0 Answers0