0Pricing
Data Science Academy · Lesson

Add, Rename, and Drop Columns

Shaping columns to fit your analysis.

Add, Rename, and Drop Columns is a free Data Science Academy lesson on CoddyKit — lesson 4 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.

Shape Columns to Fit

Real analysis means reshaping columns: adding new ones, renaming unclear ones, and dropping clutter so your table answers the question at hand. ✂️

Add a Column by Assignment

Create a new column just by assigning to a fresh name. If it does not exist yet, pandas adds it on the spot.

df["total"] = df["price"] * df["qty"]

Derive From Other Columns

New columns often come from vectorized math on existing ones. Pandas applies the formula across every row at once, no loop needed.

Add a Constant Value

Assign a single value and pandas broadcasts it to every row. Handy for tagging a batch with a source label or a flag.

df["source"] = "web"

Rename for Clarity

The rename method swaps confusing headers for clear ones using a mapping dict. Good names make later code read like plain English.

df.rename(columns={"qty": "quantity"})

Rename Many at Once

Pass several pairs in the same dict to rename multiple columns in one call. Untouched columns simply keep their original names.

df.rename(columns={"qty": "quantity", "amt": "amount"})

Drop What You Do Not Need

The drop method removes columns by name. Use axis=1, or the clearer columns argument, to target columns rather than rows.

df.drop(columns=["notes"])

Drop Several Columns

Pass a list to drop to remove many columns in one go. Trimming dead weight keeps your table focused and faster to scan.

df.drop(columns=["notes", "temp"])

Most Methods Return a Copy

By default rename and drop return a new DataFrame and leave the original untouched. Capture the result to keep your changes.

df = df.drop(columns=["notes"])

Insert at a Position

Need a column in a specific spot, not the end? The insert method places it at the index you choose among the others.

df.insert(1, "rank", ranks)

Reorder by Selection

Reorder columns simply by selecting them in the order you want. A fresh column list gives you full control over layout.

df = df[["name", "total", "source"]]

Quick Check

Choose the method that removes a column from a DataFrame.

Recap: Column Surgery

Assign to add, rename to clarify, and drop to declutter. Reassign the result and your table fits the analysis perfectly. 🧩

Frequently asked questions

Is the “Add, Rename, and Drop Columns” lesson free?

Yes — the full text of “Add, Rename, and Drop Columns” 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 “Add, Rename, and Drop Columns”?

Shaping columns to fit your analysis. 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 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Add, Rename, and Drop Columns” 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