DataFrame.append() is removed in pandas 2.0: how do you combine DataFrames now?

Quick Overview

Asks how to stack DataFrames in pandas 2.0 after the old append method was removed, and how to rewrite code that grew a DataFrame inside a loop. Tests knowledge of the replacement API, index handling, column alignment and the cost of repeated copying.

DataFrame.append() is removed in pandas 2.0: how do you combine DataFrames now?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

The `.append()` method is removed from pandas DataFrames. How do you combine DataFrames now? Code written for older pandas often grew a frame with `df = df.append(new_row, ignore_index=True)`, sometimes inside a loop, and that line now raises an `AttributeError`. ```hint Think in lists The replacement works on many frames in one call. Consider how that changes the way a loop that grows a DataFrame should be written. ``` ### What a Strong Answer Covers - The replacement function and the arguments that reproduce the old behavior, including the index - How to add a single row held as a dict or Series - Why growing a DataFrame one piece at a time inside a loop is slow, and the pattern that replaces it - What happens when the frames have different columns or dtypes ### Follow-up Questions - What is the total copying cost of calling the old append n times in a loop, compared with one combine at the end? - When would you use `merge` or `join` instead of stacking frames? - How do you record which source frame each row came from after combining them? - Why can an integer column come back as float after two frames are stacked?

Overview: Asks how to stack DataFrames in pandas 2.0 after the old append method was removed, and how to rewrite code that grew a DataFrame inside a loop. Tests knowledge of the replacement API, index handling, column alignment and the cost of repeated copying.

General logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

The .append() method is removed from pandas DataFrames. How do you combine DataFrames now?

Code written for older pandas often grew a frame with df = df.append(new_row, ignore_index=True), sometimes inside a loop, and that line now raises an AttributeError.

What a Strong Answer Covers Guidance

  • The replacement function and the arguments that reproduce the old behavior, including the index
  • How to add a single row held as a dict or Series
  • Why growing a DataFrame one piece at a time inside a loop is slow, and the pattern that replaces it
  • What happens when the frames have different columns or dtypes

Follow-up Questions Guidance

  • What is the total copying cost of calling the old append n times in a loop, compared with one combine at the end?
  • When would you use merge or join instead of stacking frames?
  • How do you record which source frame each row came from after combining them?
  • Why can an integer column come back as float after two frames are stacked?