liveBook · Manning

Pandas.concat

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

A pandas function that concatenates pandas objects along a specified axis and returns a combined object.

Think of pandas.concat as stacking compatible data tables into one larger table. It is a top-level pandas function that accepts a list of pandas objects, concatenates them along an axis, and returns a new combined object. section 2.10 section 3.6

Add products to a catalog

Create new_products with noncolliding indexes, then combine it with the existing catalog using df = pd.concat([df, new_products]). Because the new rows omit sales, pandas preserves the column and fills those entries with NaN. Select them with df.loc[[5, 6, 7], 'sales'] and assign the missing values. section 2.10

Use concatenation when separate tables represent compatible records that should be analyzed together:

  • Load July 2019 and July 2020 taxi data, add a year column to each frame, and concatenate them before comparing ride counts, revenue, or payment behavior. section 3.6
  • Load weather files for Chicago, Los Angeles, and Boston, label each frame with its city, and concatenate them before grouping and plotting. section 11.6
  • Experiment by adding one product without pd.concat, then compare that approach with concatenating a complete data frame. section 2.12
df = pd.concat([df, new_products])

Inspect the concise operation that appends new_products to the existing data frame and returns the combined frame. section 2.10

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Explains list-based concatenation, returned new objects, index concerns, missing values, and downstream analysis, but not a broad parameter catalog.
Examples
Uses product catalogs, New York taxi files from 2019 and 2020, and labeled weather data from three cities.
What it assumes
Assumes familiarity with pandas Series and DataFrames, while reinforcing index management, column assignment, and row selection.
What you can do after
Apply it via pandas to combine data frames, preserve relevant labels, inspect missing fields, and prepare unified data for analysis.
How it connects
Connects DataFrame construction, Series, indexing, missing data, grouping, aggregation, and visualization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.