Pandas Advanced Operations

Pandas Advanced Operations Quiz

Last Updated :
Discuss
Comments

Question 1

Which of the following methods can you use to select a specific column in a Pandas DataFrame?

  • df.iloc['column_name']

  • df['column_name']

  • df.select('column_name')

  • df.column_name

Question 2

What does df.loc[2, 'Age'] return when df is a DataFrame?

  • Value at index 2 in the 'Age' column

  • Value at row 2 and column 'Age'

  • Value at index 2 in the DataFrame

  • Value at row 2 and column index 2

Question 3

Which method would you use to select rows where the value in the 'Age' column is greater than 30?

  • df[df['Age'] > 30]

  • df.select_rows('Age' > 30)

  • df.query('Age > 30')

  • Both a and c

Question 4

Which of the following methods is used to group data before applying aggregation functions like sum() or mean() in Pandas?

  • df.group()

  • df.aggregate()

  • df.groupby()

  • df.group_by()

Question 5

What does the following code do?

print("GFG")

df.groupby('Category')['Price'].mean()


  • Groups data by 'Category' and finds the mean of 'Price' for each category

  • Groups data by 'Price' and calculates the mean for 'Category'

  • Filters data based on the 'Price' column

  • Creates a new column 'mean_price' in the DataFrame

Question 6

How would you get the sum of 'Sales' for each 'Region' in a DataFrame df?

  • df.groupby('Region')['Sales'].sum()

  • df['Sales'].groupby('Region').sum()

  • df.groupby('Region').sum()['Sales']

  • Both a and c

Question 7

What is the result of using pd.merge(df1, df2, on='ID')?

  • Concatenates two DataFrames

  • Merges two DataFrames based on the 'ID' column

  • Joins two DataFrames with an outer join

  • Joins two DataFrames with a left join

Question 8

Which of the following types of joins can be specified in pd.merge()?

  • Inner join

  • Left join

  • Right join

  • All of the above

Question 9

If df1 has a column 'ID' and df2 has a column 'UserID', what should you do to merge them based on these columns?

  • pd.merge(df1, df2, on='ID')

  • pd.merge(df1, df2, left_on='ID', right_on='UserID')

  • df1.merge(df2, left='ID', right='UserID')

  • Both b and c

Question 10

What does df.sort_values('Age', ascending=False) do?

  • Sorts the DataFrame by 'Age' in ascending order

  • Sorts the DataFrame by 'Age' in descending order

  • Sorts the DataFrame by 'Age' in alphabetical order

  • None of the above

Tags:

There are 15 questions to complete.

Take a part in the ongoing discussion