0
0
Pandasdata~10 mins

DataFrame as labeled two-dimensional table in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a DataFrame from a dictionary.

Pandas
import pandas as pd

data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.[1](data)
print(df)
Drag options to blanks, or click blank then click option'
ASeries
BPanel
CDataFrame
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using Series instead of DataFrame creates a one-dimensional structure.
Using Panel is deprecated and not suitable here.
2fill in blank
medium

Complete the code to select the 'Age' column from the DataFrame.

Pandas
import pandas as pd

data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.DataFrame(data)
age_column = df[1]
print(age_column)
Drag options to blanks, or click blank then click option'
A[['Age']]
B['Age']
C.Age()
D.Age
Attempts:
3 left
💡 Hint
Common Mistakes
Using double brackets returns a DataFrame, not a Series.
Using dot notation with parentheses is invalid.
3fill in blank
hard

Fix the error in the code to access the first row using .iloc.

Pandas
import pandas as pd

data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.DataFrame(data)
first_row = df.iloc[1]
print(first_row)
Drag options to blanks, or click blank then click option'
A(0)
B0
C[[0]]
D[0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets causes a TypeError.
Using double brackets returns a DataFrame instead of a Series.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 characters.

Pandas
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: [1] for word in words if [2]
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Bword > 3
Clen(word) > 3
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself instead of its length.
Comparing the word string directly to a number.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths for words longer than 3 characters.

Pandas
words = ['apple', 'bat', 'carrot', 'dog']
lengths = { [1]: [2] for word in words if [3] }
print(lengths)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 3
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word instead of uppercase.
Not filtering words by length.