0
0
Pandasdata~5 mins

merge() for SQL-like joins in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the pandas merge() function do?
It combines two DataFrames based on common columns or indices, similar to SQL joins.
Click to reveal answer
beginner
What are the main types of joins you can perform with merge()?
  • Inner join: keeps only matching rows
  • Left join: keeps all rows from left DataFrame
  • Right join: keeps all rows from right DataFrame
  • Outer join: keeps all rows from both DataFrames
Click to reveal answer
beginner
How do you specify the columns to join on in merge()?
Use the on parameter with a column name or list of column names that exist in both DataFrames.
Click to reveal answer
beginner
What happens if you use how='left' in merge()?
All rows from the left DataFrame are kept. Matching rows from the right DataFrame are added. If no match, right side columns have NaN.
Click to reveal answer
intermediate
What is the difference between merge() and concat() in pandas?
merge() joins DataFrames based on keys (like SQL joins). concat() stacks DataFrames vertically or horizontally without matching keys.
Click to reveal answer
Which how parameter in merge() keeps only rows that appear in both DataFrames?
Aright
Bleft
Cinner
Douter
If you want to keep all rows from the right DataFrame and add matching rows from the left, which how do you use?
Ainner
Bright
Cleft
Douter
What parameter do you use to specify the column(s) to join on in merge()?
Akey
Bby
Cjoin
Don
What will be the result of an outer join?
AAll rows from both DataFrames, filling missing with NaN
BAll rows from the left DataFrame only
COnly rows common to both DataFrames
DOnly rows from the right DataFrame
Which pandas function stacks DataFrames without matching keys?
Aconcat()
Bmerge()
Cjoin()
Dgroupby()
Explain how to use pandas merge() to combine two DataFrames with a left join.
Think about keeping all rows from the first DataFrame and matching from the second.
You got /4 concepts.
    Describe the difference between inner join and outer join in pandas merge().
    Consider which rows are kept in each join type.
    You got /3 concepts.