0

I have two dictionary dict1 and dict2

I am trying to load them using JSON

import json

y = json.loads(json.dumps([dict1, dict2]))

then trying to convert that to pdf

import pandas as pd

df = pd.DataFrame.from_dict(y, orient='index')

I am getting below error

AttributeError: 'str' object has no attribute 'values'

when I do it for one dictionary dict1

x = json.loads(dict1)
df_x = pd.DataFrame.from_dict(x, orient = 'index')

It is working. I understand that in second case as x is loading as dictionary it is able to convert to dataframe. But, first case, as it is a list it is not working.

So, how can I convert list of dictionaries to dataframe?

FBruzzesi
  • 6,385
  • 3
  • 15
  • 37
S.Dasgupta
  • 61
  • 9
  • 1
    Possible duplicate of [Convert list of dictionaries to Dataframe](https://stackoverflow.com/questions/20638006/convert-list-of-dictionaries-to-dataframe). – jpp Jul 31 '18 at 13:32
  • Possible duplicate of [Convert list of dictionaries to Dataframe](https://stackoverflow.com/questions/20638006/convert-list-of-dictionaries-to-dataframe) – Karthik V Jul 31 '18 at 14:48

0 Answers0