0
0
Pandasdata~10 mins

Arithmetic operations on 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 add two columns 'A' and 'B' in the DataFrame and store the result in a new column 'C'.

Pandas
df['C'] = df['A'] [1] df['B']
Drag options to blanks, or click blank then click option'
A-
B/
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' or '/' instead of '+' for addition.
Forgetting to use brackets around column names.
2fill in blank
medium

Complete the code to subtract column 'B' from column 'A' and save it in column 'D'.

Pandas
df['D'] = df['A'] [1] df['B']
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' for subtraction.
Mixing up the order of columns.
3fill in blank
hard

Fix the error in the code to multiply columns 'A' and 'B' correctly and store in 'E'.

Pandas
df['E'] = df['A'] [1] df['B']
Drag options to blanks, or click blank then click option'
A+
B-
C/
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' instead of '*' for multiplication.
Using '/' which divides instead of multiplies.
4fill in blank
hard

Fill both blanks to divide column 'A' by column 'B' and store the result in column 'F'.

Pandas
df['F'] = df[[1]] [2] df['B']
Drag options to blanks, or click blank then click option'
A'A'
B'B'
C/
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' instead of '/' for division.
Using wrong column names in the code.
5fill in blank
hard

Fill all three blanks to create a new column 'G' with the sum of columns 'A' and 'B' multiplied by column 'C'.

Pandas
df['G'] = (df[[1]] [2] df[[3]]) * df['C']
Drag options to blanks, or click blank then click option'
A'A'
B'B'
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' instead of '+' for addition.
Mixing up the order of columns.