Data science

Stage 1 · Lesson 6 of 7

Joining tables

Python for data: NumPy and pandas

Real data arrives in pieces: orders in one file, customers in another, products in a third. A combines two tables on a key column, like a SQL join. A left join keeps every row of the left table and adds matching columns from the right, filling gaps with missing values when there is no match.

In it is merge; in dplyr it is left_join and its siblings. Always check the row count before and after a join, and tell the tool what relationship you expect, such as many orders to one customer, so it errors when that is false.

Common trapjoining on a key that is not unique in the lookup table: every duplicate multiplies rows and inflates every total that follows, with no error message.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking Python Fundamentals

    Design Gurus · Beginner · $50

    Solid Python basics first: data types, collections, functions and files, the ground pandas stands on

  • CourseFree
    Kaggle Learn

    Kaggle · Beginner

    Free: the Python and Pandas courses, short lessons with exercises that run in the browser

Practise

  • Pick one dataset on a topic you care about and repeat every operation in this stage on it

Keep handy

  • The indexing, merging and reshaping pages answer most "how do I" questions

  • The absolute beginners guide, then the reference when an array does something unexpected

Also worth your time

Mark this stage as not done?