
Pandas_Ops
Authored by Navneet Sadh
Computers
12th Grade
Used 3+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
9 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
How do you select all rows and only specific columns in a DataFrame using the loc() method?
df.loc[:, columns]
df.loc[rows, :]
df.loc[rows, columns]
df.loc[:, rows]
Answer explanation
To select all rows and only specific columns in a DataFrame using the loc method, we can pass the : and columns as arguments to the loc method. Using df.loc[:, columns] will select all rows and only the specified columns.
2.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
Which slicing operation is used to select rows from index 2 to index 5 (inclusive) in a DataFrame?
df.loc[2:6]
df.iloc[2:5]
df.iloc[2:6]
df.loc[2:5]
Answer explanation
Slicing notation df.iloc[2:6] is used to select rows from index 2 to index 5 (inclusive) in a DataFrame. The ending index is exclusive, so using [2:6] will select rows with indices 2, 3, 4 and 5.
3.
MULTIPLE CHOICE QUESTION
1 min • 1 pt
How do you add a new row to a DataFrame using the loc() method?
df.loc[row_label] = row_data
df.loc[:, row_label] = row_data
df.loc[row_data, row_label]
df.loc[row_data] = row_label
Answer explanation
To add a new row to a DataFrame using the loc method, we can assign the row data to a new row label. Using df.loc[row_label] = row_data will add a new row with the specified label and corresponding data.
4.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Given a DataFrame df, write a code snippet to delete the column named Salary.
Given a DataFrame df, write a code snippet to delete the column named Salary.
df.drop(Salary, axis=1)
df.drop('Salary',inplace=True)
df.remove(Salary)
df=df.drop('Salary',axis=1,inplace=False)
Answer explanation
To delete a column named "Salary" from a DataFrame, we can use the drop method with axis=1 to indicate that we are dropping a column. Using df=df.drop("Salary", axis=1,inplace=False) will delete the "Salary" column.
5.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
How do you delete a third row named row_3 from a DataFrame using the drop() method?
df.drop(row_3,inplace=True)
df.drop(df.index[2],inplace='True')
df.drop('row_3',axis=1,inplace='True')
df.drop('row_3')
Answer explanation
To delete a specific row named "row_3" from a DataFrame, we can use the drop method with:
df.index[2] to get the label of third row.
axis=0
and
inplace=True
6.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Given a DataFrame df with columns A and B, write a code snippet to rename the row index from 'old_index' to 'new_index'.
df=df.rename(index={'old_index': 'new_index'})
df=df.rename(index=['old_index', 'new_index'])
df=df.rename(index='old_index', new_index='new_index')
df.rename({'old_index': 'new_index'},axis=0)
Answer explanation
To rename the row index from "old_index" to "new_index" in a DataFrame, we can use the rename method and pass a dictionary to the index parameter. Using df.rename(index={'old_index': 'new_index'}) will rename the row index accordingly.
As iplace is false by default save the copy in the df itself.
7.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
How do you delete columns with names ['col1', 'col2', 'col3'] from a DataFrame df using the drop() method?
df.drop(['col1', 'col2', 'col3'])
df=df.drop(['col1', 'col2', 'col3'], axis=0)
df.drop(['col1', 'col2', 'col3'], axis=1)
df.drop(['col1', 'col2', 'col3'],axis=1, inplace=True)
Answer explanation
To delete columns with names "col1", "col2", and "col3" from a DataFrame, we can use the drop method with axis=1 to indicate that we are dropping columns. Using
df.drop(['col1', 'col2', 'col3'],axis=1, inplace=True) will delete the specified columns.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
11 questions
Software dan Hardware
Quiz
•
12th Grade
10 questions
Tool Photoshop
Quiz
•
9th - 12th Grade
10 questions
Penilaian Harian-1, Pemrograman Berorientasi Objek (PBO)
Quiz
•
12th Grade
10 questions
Hari 3 - Kuis Coding & Perkenalan AI
Quiz
•
8th Grade - University
10 questions
Software Design and Development Quick Quiz 3
Quiz
•
11th - 12th Grade
10 questions
Initial Assessment - Cybersecurity Awareness
Quiz
•
9th Grade - Professio...
11 questions
Cyber Security Solutions
Quiz
•
9th - 12th Grade
12 questions
Incident Response Policy 1 Quiz
Quiz
•
12th Grade
Popular Resources on Wayground
7 questions
History of Valentine's Day
Interactive video
•
4th Grade
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
15 questions
Valentine's Day Trivia
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
Discover more resources for Computers
18 questions
Valentines Day Trivia
Quiz
•
3rd Grade - University
20 questions
-AR -ER -IR present tense
Quiz
•
10th - 12th Grade
21 questions
Presidents Day Trivia
Quiz
•
6th - 12th Grade
10 questions
Valentine's Day: History and Modern Celebration
Interactive video
•
9th - 12th Grade
11 questions
Valentine's Day Trivia
Quiz
•
8th - 12th Grade
10 questions
Factor Quadratic Expressions with Various Coefficients
Quiz
•
9th - 12th Grade
18 questions
Success Strategies
Quiz
•
9th - 12th Grade
10 questions
Valentine's Day Trivia
Quiz
•
9th - 12th Grade