Pandas Load Dataframe

February 21, 2021

List of dict

import pandas as pd 

items = [
  {'name': 'Desmond', 'rank': 1},
  {'name': 'Jack', 'rank': 2},
  {'name': 'Elon', 'rank': 3}
]

df = pd.DataFrame(items) 
      name  rank
0  Desmond     1
1     Jack     2
2     Elon     3

List of list

import pandas as pd 

items = [
  ['Desmond', 1],
  ['Jack', 2],
  ['Elon', 3]
]

df = pd.DataFrame(items, columns=['name', 'rank']) 
      name  rank
0  Desmond     1
1     Jack     2
2     Elon     3

Separate List for each column

import pandas as pd 

names = ['Desmond', 'Jack', 'Elon']
ranks = [1, 2, 3]

df = pd.DataFrame({'name': names, 'rank': ranks}) 
      name  rank
0  Desmond     1
1     Jack     2
2     Elon     3
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.