0
0
Data Analysis Pythondata~5 mins

concat() for stacking DataFrames in Data Analysis Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the concat() function do in pandas?
The concat() function joins multiple DataFrames together either vertically (stacking rows) or horizontally (stacking columns).
Click to reveal answer
beginner
How do you stack two DataFrames vertically using concat()?
Use pd.concat([df1, df2]) to stack rows of df2 below df1. By default, it stacks vertically (axis=0).
Click to reveal answer
beginner
What parameter controls whether concat() stacks DataFrames horizontally or vertically?
The axis parameter: axis=0 stacks vertically (rows), axis=1 stacks horizontally (columns).
Click to reveal answer
intermediate
What happens if the DataFrames have different columns when stacked vertically with concat()?
Missing columns in each DataFrame become NaN in the result, so all columns from all DataFrames appear.
Click to reveal answer
intermediate
How can you reset the index after stacking DataFrames with concat()?
Use ignore_index=True inside concat() to reset the index in the combined DataFrame.
Click to reveal answer
What is the default axis value for pd.concat() when stacking DataFrames?
A0 (vertical stacking)
B1 (horizontal stacking)
C-1 (reverse stacking)
DNone (no stacking)
If two DataFrames have different columns, what does concat() do when stacking vertically?
AFills missing columns with NaN
BDuplicates columns
CRaises an error
DDrops columns not common to both
How do you stack DataFrames side-by-side (horizontally) using concat()?
ASet <code>axis=0</code>
BUse <code>join='outer'</code>
CUse <code>ignore_index=True</code>
DSet <code>axis=1</code>
What does ignore_index=True do in concat()?
AKeeps original indexes
BResets index in the combined DataFrame
CDrops duplicate rows
DSorts the DataFrame
Which pandas function is used to stack DataFrames?
Agroupby()
Bmerge()
Cconcat()
Dpivot()
Explain how to stack two DataFrames vertically using concat() and how to handle their indexes.
Think about stacking rows and index resetting.
You got /3 concepts.
    Describe what happens when you stack DataFrames with different columns using concat().
    Consider how pandas handles missing data in combined DataFrames.
    You got /3 concepts.