0
0
Pandasdata~10 mins

Why Pandas performance matters - Test Your Understanding

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
BDataFrame
Carray
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using pd.Series instead of pd.DataFrame
Trying to create a list or array instead of a DataFrame
2fill in blank
medium

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

Pandas
ages = df[1]['age']
print(ages)
Drag options to blanks, or click blank then click option'
A.loc
B.iloc
C.select
D[
Attempts:
3 left
💡 Hint
Common Mistakes
Using .loc without brackets
Using .select which is not a pandas method
3fill in blank
hard

Fix the error in the code to filter rows where age is greater than 25.

Pandas
filtered = df[df['age'] [1] 25]
print(filtered)
Drag options to blanks, or click blank then click option'
A>
B<
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >
Using == which checks equality
4fill in blank
hard

Complete the code to create a dictionary comprehension that maps names to ages for people older than 25.

Pandas
result = {person: age for person, age in zip(df['name'], df['age']) if age [1] 25}
print(result)
Drag options to blanks, or click blank then click option'
A:
B>
C<
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using = instead of : in dictionary comprehension
Using < instead of > in the condition
5fill in blank
hard

Fill all three blanks to create a DataFrame from a dictionary, select the 'score' column, and filter scores above 80.

Pandas
data = {'name': ['Ann', 'Ben'], 'score': [85, 75]}
df = pd.[1](data)
high_scores = df[df[[2]] [3] 80]
print(high_scores)
Drag options to blanks, or click blank then click option'
ADataFrame
B'score'
C>
DSeries
Attempts:
3 left
💡 Hint
Common Mistakes
Using pd.Series instead of pd.DataFrame
Not quoting the column name
Using < instead of > for filtering