Complete the code to create a DataFrame from a dictionary.
import pandas as pd data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]} df = pd.[1](data) print(df)
The DataFrame constructor creates a labeled two-dimensional table from the dictionary.
Complete the code to select the 'Age' column from the DataFrame.
import pandas as pd data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]} df = pd.DataFrame(data) age_column = df[1] print(age_column)
Using df['Age'] selects the 'Age' column as a Series.
Fix the error in the code to access the first row using .iloc.
import pandas as pd data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]} df = pd.DataFrame(data) first_row = df.iloc[1] print(first_row)
The iloc indexer requires square brackets to select rows by position. Use df.iloc[0] to get the first row.
Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2] print(lengths)
The dictionary comprehension maps each word to its length using len(word). The condition len(word) > 3 filters words longer than 3 characters.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = { [1]: [2] for word in words if [3] } print(lengths)
The dictionary comprehension uses word.upper() as keys, maps to len(word), and filters words with length greater than 3.