0
0
Pandasdata~10 mins

Selecting multiple columns 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 select columns 'A' and 'B' from the DataFrame df.

Pandas
selected = df[[[1]]]
Drag options to blanks, or click blank then click option'
A["A", "B"]
B"AB"
C("A", "B")
D"A, B"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string with comma instead of a list.
Using parentheses instead of brackets.
Selecting columns without double brackets.
2fill in blank
medium

Complete the code to select columns 'Name' and 'Age' from the DataFrame data.

Pandas
subset = data[[[1]]]
Drag options to blanks, or click blank then click option'
A("Name", "Age")
B["Name", "Age"]
C"Name, Age"
D"NameAge"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string with commas instead of a list.
Using parentheses instead of square brackets.
3fill in blank
hard

Fix the error in selecting columns 'X' and 'Y' from df.

Pandas
result = df[[1]]
Drag options to blanks, or click blank then click option'
A["X", "Y"]
B"X, Y"
C("X", "Y")
D"XY"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string with commas instead of a list.
Using parentheses instead of square brackets.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 4 letters.

Pandas
lengths = { [1] : [2] for word in words if len(word) > 4 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Cword.upper()
Dlen(words)
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(words) instead of len(word).
Using word.upper() as key instead of word.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys, their lengths as values, but only for words longer than 3 letters.

Pandas
result = { [1] : [2] for word in words if [3] > 3 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of word.upper() as key.
Using word instead of len(word) in condition.