Recall & Review
beginner
What does the
append() method do in pandas?It adds rows of one DataFrame to the end of another DataFrame, combining them vertically.
Click to reveal answer
beginner
How can you combine two DataFrames vertically without using
append()?You can use
pd.concat([df1, df2]) to join DataFrames vertically, which is the recommended way since append() is deprecated.Click to reveal answer
intermediate
What is the main difference between
append() and concat() in pandas?append() is a simpler method to add rows but is deprecated. concat() is more flexible and can combine multiple DataFrames along different axes.Click to reveal answer
beginner
Show a simple example of using
pd.concat() to combine two DataFrames df1 and df2.Example:<br><pre>import pandas as pd
df1 = pd.DataFrame({'A': [1, 2]})
df2 = pd.DataFrame({'A': [3, 4]})
result = pd.concat([df1, df2])
print(result)</pre>Click to reveal answer
beginner
Why is
pd.concat() preferred over append() in recent pandas versions?append() is deprecated and will be removed in future versions. pd.concat() is more powerful and consistent for combining DataFrames.Click to reveal answer
Which pandas function is recommended to combine DataFrames vertically now that
append() is deprecated?✗ Incorrect
pd.concat() is the recommended function to combine DataFrames vertically, replacing append().What does
pd.concat([df1, df2]) do by default?✗ Incorrect
By default,
pd.concat() stacks DataFrames vertically (adds rows).If you want to combine DataFrames side-by-side (columns), which
pd.concat() parameter should you change?✗ Incorrect
Setting
axis=1 concatenates DataFrames horizontally (by columns).What happens if you use
pd.concat() on DataFrames with different columns?✗ Incorrect
Missing columns in each DataFrame are filled with NaN when concatenated.
Why might you want to use
ignore_index=True with pd.concat()?✗ Incorrect
ignore_index=True resets the row index after concatenation.Explain how to combine two pandas DataFrames vertically without using the deprecated
append() method.Think about a function that stacks DataFrames on top of each other.
You got /5 concepts.
Describe the differences and advantages of using
pd.concat() over append() in pandas.Consider flexibility and future compatibility.
You got /5 concepts.