Complete the code to stack two DataFrames vertically using concat.
import pandas as pd df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) df2 = pd.DataFrame({'A': [5, 6], 'B': [7, 8]}) result = pd.concat([df1, df2], axis=[1]) print(result)
To stack DataFrames vertically (one on top of the other), use axis=0 in pd.concat().
Complete the code to reset the index after stacking DataFrames vertically.
import pandas as pd df1 = pd.DataFrame({'X': [10, 20]}) df2 = pd.DataFrame({'X': [30, 40]}) stacked = pd.concat([df1, df2], axis=0) stacked_reset = stacked.[1](drop=True) print(stacked_reset)
reindex does not reset the index numbering.reset_index.After stacking, the index may be duplicated. Use reset_index(drop=True) to reset it to a clean sequence.
Fix the error in the code to stack DataFrames horizontally.
import pandas as pd df1 = pd.DataFrame({'A': [1, 2]}) df2 = pd.DataFrame({'B': [3, 4]}) result = pd.concat([df1, df2], axis=[1]) print(result)
To stack DataFrames side by side (horizontally), use axis=1 in pd.concat().
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['apple', 'bat', 'car', 'door'] lengths = {word: [1] for word in words if [2] print(lengths)
The dictionary maps each word to its length using len(word). The condition keeps words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 3.
words = ['apple', 'bat', 'car', 'door'] result = { [1]: [2] for word in words if [3] } print(result)
The dictionary keys are uppercase words using word.upper(), values are lengths with len(word), and the condition filters words longer than 3 characters.