3

This is what one row of themesdf looks like:

[{'code': '1', 'name': 'Economic management'},
 {'code': '6', 'name': 'Social protection and risk management'}]

I want to normalize each row and add it to a newdf. This is what I have right now:

import pandas as pd

themesdf = json_df['mjtheme_namecode']
newdf = pd.DataFrame()
%timeit() 
for row in themesdf:
    for item in row:
        newdf.append(json_normalize(item, 'name'))
newdf

After printing out newdf, it comes it with nothing. My ultimate goal with this data is to get the top ten major project themes (column 'name').

FBruzzesi
  • 5,942
  • 3
  • 14
  • 35
vnguyen56
  • 45
  • 5
  • 1
    `newdf = newdf.append(json_normalize(item, 'name'))` As the [docs](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.append.html) `.append()` returns a new object. So you need to update the dataframe. – harvpan Jul 17 '18 at 19:53
  • 2
    **[Never call DataFrame.append or pd.concat inside a for-loop. It leads to quadratic copying.](https://stackoverflow.com/a/36489724/1422451)** – Parfait Jul 17 '18 at 20:55

0 Answers0