0
0
Pandasdata~10 mins

Dropping columns and rows 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 drop the column named 'Age' from the DataFrame df.

Pandas
df = df.drop([1], axis=1)
Drag options to blanks, or click blank then click option'
A'Age', axis=1
B'age'
C'Age'
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name with incorrect case.
Not specifying axis=1 when dropping a column.
2fill in blank
medium

Complete the code to drop the row with index label 3 from the DataFrame df.

Pandas
df = df.drop([1], axis=0)
Drag options to blanks, or click blank then click option'
A3
B'3'
C'index=3'
Ddf.index[3]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the index as a string instead of an integer.
Confusing axis=0 and axis=1.
3fill in blank
hard

Fix the error in the code to drop the column 'Salary' from df.

Pandas
df.drop([1], axis=1, inplace=True)
Drag options to blanks, or click blank then click option'
A['Salary']
BSalary
C'salary'
D'Salary'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the column name.
Using wrong case for the column name.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if the length is greater than 3.

Pandas
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using the word in the condition instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their counts only if the count is greater than 0.

Pandas
{ [1]: [2] for [3] in data.items() if [2] > 0 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using data instead of k or v in the comprehension.
Not converting keys to uppercase.