0
0
Pandasdata~10 mins

replace() for value substitution 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 replace all occurrences of 0 with 100 in the DataFrame column 'score'.

Pandas
df['score'] = df['score'].[1](0, 100)
Drag options to blanks, or click blank then click option'
Areplace
Bsubstitute
Cswap
Dchange
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like 'substitute' or 'swap' which do not exist in pandas.
Trying to assign values directly without using a method.
2fill in blank
medium

Complete the code to replace the string 'low' with 'L' in the 'level' column of the DataFrame.

Pandas
df['level'] = df['level'].[1]('low', 'L')
Drag options to blanks, or click blank then click option'
Areplace
Bswap
Cchange
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'swap' or 'update'.
Trying to replace values without calling a method.
3fill in blank
hard

Fix the error in the code to replace 1 with 10 in the 'count' column.

Pandas
df['count'] = df['count'].[1](1, 10)
Drag options to blanks, or click blank then click option'
Aswitch
Breplace
Csubstitute
Dchange
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods that do not exist in pandas like 'substitute' or 'switch'.
Misspelling the method name.
4fill in blank
hard

Fill both blanks to create a dictionary that replaces 'A' with 'Alpha' in the 'grade' column.

Pandas
df['grade'] = df['grade'].replace([1]: [2])
Drag options to blanks, or click blank then click option'
A'A'
B'Alpha'
C'B'
D'Beta'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping keys and values in the dictionary.
Not using quotes around string keys and values.
5fill in blank
hard

Fill all three blanks to replace 0 with 'Zero' and 1 with 'One' in the 'number' column using a dictionary.

Pandas
df['number'] = df['number'].replace([1]: [2], [3]: 'One'})
Drag options to blanks, or click blank then click option'
A0
B'Zero'
C1
D'One'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around keys which are numbers.
Not closing the dictionary properly.