How to append a dictionary to a pandas dataframe?

后端 未结 2 1667
孤城傲影
孤城傲影 2021-02-14 03:59

I have a set of urls containing json files and an empty pandas dataframe with columns representing the attributes of the jsnon files. Not all json files have all the attributes

2条回答
  •  無奈伤痛
    2021-02-14 04:30

    For me below code works:

    row = -1
    for i in links:
        row = row + 1
        data = urllib2.urlopen(str(i)).read()
        data = json.loads(data)
        for key in data.keys():
            df.loc[row,key] = data[key]
    

    You have mixed order of arguments in .loc() and have one to much []

提交回复
热议问题