Create A DataFrame from dictionary


In [1]:
import pandas as pd

In [2]:
data = [{'name': 'vikash', 'age': 27}, {'name': 'Satyam', 'age': 14}]

In [3]:
df = pd.DataFrame.from_dict(data, orient='columns')

In [4]:
df


Out[4]:
age name
0 27 vikash
1 14 Satyam

If the Dictionary is nested you first need to normalize it


In [5]:
from pandas.io.json import json_normalize

In [6]:
data = [
  {
    'name': {
      'first': 'vikash',
      'last': 'singh'
    },
    'age': 27
  },
  {
    'name': {
      'first': 'satyam',
      'last': 'singh'
    },
    'age': 14
  }
]

In [7]:
df = pd.DataFrame.from_dict(json_normalize(data), orient='columns')

In [8]:
df


Out[8]:
age name.first name.last
0 27 vikash singh
1 14 satyam singh

In [ ]: