Tsallaka zuwa abun ciki
Justice Tech School

Creating DataFrames

Build from a dict of lists, a list of dicts or a NumPy array.

Example
a = pd.DataFrame({"x": [1, 2], "y": [3, 4]})
b = pd.DataFrame([{"x": 1, "y": 3}, {"x": 2, "y": 4}])
c = pd.DataFrame(np.arange(4).reshape(2, 2), columns=["p", "q"])
print(a.equals(b))
print(c)

Result

True
   p  q
0  0  1
1  2  3

Exercise

From records.

pd.DataFrame([{"a": 1}, ])

Quiz Test

Can a DataFrame come from a list of dicts?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.