title: How to unnest elements of a list that are dictionaries into dataframe (using the first values of it as prefixes)
body: <p>I am currently studying python (using pandas) for dealing with data analysis. I did a few courses on DataCamp and tried to apply what I've learned into a real problem: I wanted to monitor covid-19 cases in Canada.</p>
  
  <p>For that I am getting the data from an Apify API which returns a json that I then create a dataframe from. The dataframe structure can be seen below:</p>
  
  <pre><code>&lt;class 'pandas.core.frame.DataFrame'&gt;
  Int64Index: 57 entries, 0 to 56
  Data columns (total 9 columns):
  infected              57 non-null float64
  deceased              57 non-null float64
  infectedByRegion      57 non-null object
  measureDate           57 non-null object
  measureTime           57 non-null object
  </code></pre>
  
  <p>The infected and deceased columns contains the total numbers for Canada.</p>
  
  <p>Inside the infectedByRegion column, I have a list of dictionaries in each row as follows:</p>
  
  <pre><code>   [{'region': 'Canada', 'infectedCount': '6258', 'deceasedCount': '61'},
   {'region': 'Newfoundland and Labrador',
    'infectedCount': '135',
    'deceasedCount': '0'},
   {'region': 'Prince Edward Island',
    'infectedCount': '11',
    'deceasedCount': '0'},
   {'region': 'Nova Scotia', 'infectedCount': '122', 'deceasedCount': '0'},
   {'region': 'New Brunswick', 'infectedCount': '66', 'deceasedCount': '0'},
   {'region': 'Quebec', 'infectedCount': '2840', 'deceasedCount': '22'},
   {'region': 'Ontario', 'infectedCount': '1355', 'deceasedCount': '19'},
   {'region': 'Manitoba', 'infectedCount': '72', 'deceasedCount': '1'},
   {'region': 'Saskatchewan', 'infectedCount': '134', 'deceasedCount': '0'},
   {'region': 'Alberta', 'infectedCount': '621', 'deceasedCount': '2'},
   {'region': 'British Columbia', 'infectedCount': '884', 'deceasedCount': '17'},
   {'region': 'Yukon', 'infectedCount': '4', 'deceasedCount': '0'},
   {'region': 'Northwest Territories',
    'infectedCount': '1',
    'deceasedCount': '0'},
   {'region': 'Nunavut', 'infectedCount': '0', 'deceasedCount': '0'},
   {'region': 'Repatriated travellers',
    'infectedCount': '13',
    'deceasedCount': '0'}]
  </code></pre>
  
  <p>I am trying to create columns at the end of the dataframe for each region's infected and deceased count. Example:</p>
  
  <pre><code>... measureTime   Quebec_infectedCount   Quebec_deceasedCount   Ontario_infectedCount  ...
  ... 22:30:15      2840                   22                     1355                   ...
  </code></pre>
  
  <p>I've tried using json_normalize function, but it threw me an error:</p>
  
  <pre><code>AttributeError: 'list' object has no attribute 'values'
  </code></pre>
  
  <p>Then I tried to look here at stackoverflow, and I found this link: </p>
  
  <p><a href="https://stackoverflow.com/questions/45325208/python-json-normalize-a-pandas-series-gives-typeerror">Python: json_normalize a pandas series gives TypeError</a></p>
  
  <p>Which it didn't work for me, as it only created a single column called region that contained only 'Canada' as a value in each row at the end of the data frame</p>
  
  <pre><code>... measureDate     measureTime     region
  ... 2020-03-29      22:30:15        Canada
  ... 2020-03-30      22:30:15        Canada
  </code></pre>
  
  <p>Can someone help or point me to an appropriate post here as stackoverflow that help me solve my problem? As I am still a beginner I tried to search for a couple of hours, but I think I don't even know how to frame my question precisely but really want to learn how to handle this type of situation.</p>
  
  <p>Thanks in advance!</p>