Complete the code to combine two DataFrames vertically using pandas.
import pandas as pd df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) df2 = pd.DataFrame({'A': [5, 6], 'B': [7, 8]}) combined = pd.[1]([df1, df2]) print(combined)
The concat function stacks DataFrames vertically by default, combining rows.
Complete the code to merge two DataFrames on column 'key'.
import pandas as pd df1 = pd.DataFrame({'key': ['K0', 'K1'], 'A': [1, 2]}) df2 = pd.DataFrame({'key': ['K0', 'K1'], 'B': [3, 4]}) merged = pd.merge(df1, df2, on=[1]) print(merged)
The on parameter specifies the column to join on, here it is 'key'.
Fix the error in the code to join two DataFrames on their indexes.
import pandas as pd df1 = pd.DataFrame({'A': [1, 2]}, index=['a', 'b']) df2 = pd.DataFrame({'B': [3, 4]}, index=['a', 'b']) joined = df1.[1](df2, how='inner') print(joined)
The join method joins DataFrames on their indexes by default.
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). The condition filters words longer than 3.