0Pricing
Data Science Academy · Lesson

Build a DataFrame From Scratch

From dicts, lists, and arrays.

Build a DataFrame From Scratch is a free Data Science Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Build Your Own

Before loading real files, building a small DataFrame by hand lets you test ideas and learn the structure with zero setup. 🧪

Import pandas First

Every project starts the same way: import pandas under the nickname pd. That short alias is a universal convention you will see everywhere.

import pandas as pd

From a Dictionary of Columns

The most common recipe is a dict where each key is a column name and each value is a list of that column's data.

df = pd.DataFrame({"name": ["Ada", "Lin"], "age": [36, 41]})

Keys Become Headers

With the dict approach, the dictionary keys turn into your column headers automatically. Naming columns is as easy as naming keys.

From a List of Rows

You can also pass a list of rows and supply the column names separately. Handy when your data already arrives row by row.

pd.DataFrame([["Ada", 36], ["Lin", 41]], columns=["name", "age"])

From a List of Dicts

A list of dicts works too, with one dict per row. Missing keys simply become blanks, which is great for uneven records.

pd.DataFrame([{"name": "Ada"}, {"name": "Lin", "age": 41}])

From a NumPy Array

Have a NumPy array of numbers? Pass it straight in and add column names. This bridges fast NumPy math with labeled tables.

pd.DataFrame(arr, columns=["x", "y"])

Set the Index on Creation

Pass an index argument to label your rows the moment you build the frame, instead of relying on default 0, 1, 2 numbers.

pd.DataFrame(data, index=["r1", "r2"])

Control the Column Order

Want columns in a specific order? Pass a columns list and pandas arranges them exactly as you list, ignoring dict ordering quirks.

pd.DataFrame(data, columns=["age", "name"])

Lengths Must Match

Every column you provide must have the same length. Mismatched list sizes raise an error, so keep your columns even.

Peek at What You Built

After building, glance at dtypes to confirm pandas inferred sensible types like int for ages and object for names.

df.dtypes

Quick Check

Pick the building block behind the most common DataFrame recipe.

Recap: Many Ways In

Dicts, lists, list-of-dicts, or NumPy arrays all become a DataFrame. Pick whatever matches the shape of your data. 🛠️

Frequently asked questions

Is the “Build a DataFrame From Scratch” lesson free?

Yes — the full text of “Build a DataFrame From Scratch” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “Build a DataFrame From Scratch”?

From dicts, lists, and arrays. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Build a DataFrame From Scratch” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Rows, Columns, and the Index
  2. Build a DataFrame From Scratch
  3. head, info, and describe
  4. Add, Rename, and Drop Columns
← Back to Data Science Academy