Create a DataFrame
Build a DataFrame from a dict of lists (columns), a list of dicts (rows) or a list of lists plus column names.
Example
import pandas as pd
import numpy as np
a = pd.DataFrame({'x': [1, 2], 'y': [3, 4]})
b = pd.DataFrame([{'x': 1, 'y': 3}, {'x': 2, 'y': 4}])
c = pd.DataFrame([[1, 3], [2, 4]], columns=['x', 'y'])
print(a.equals(b), a.equals(c))
print(a)Result
True True x y 0 1 3 1 2 4
Exercise
Build from rows.
pd.DataFrame([[1, 2]], =["a", "b"])
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.