Python Pandas DataFrames Quiz
A 35-question quiz covering Pandas DataFrame operations, including column manipulation, row filtering, data import, statistics, missing values, and data types.
Question 1
You have a DataFrame `df` with columns 'Name', 'Age', and 'City'. How do you select just the 'Name' column as a Series?
import pandas as pd
data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30], 'City': ['NY', 'LA']}
df = pd.DataFrame(data)
Question 2
What is the correct syntax to add a new column 'Bonus' to an existing DataFrame `df`, where every value is 100?
Question 3
How do you rename the column 'Age' to 'Years' in place?
df = pd.DataFrame({'Age': [20, 30]})
# Rename command
Question 4
Which command drops the column 'City' from the DataFrame `df`?
Question 5
You want to create a new column 'Total' that is the sum of columns 'A' and 'B'. Which syntax is most efficient and readable?
df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
Question 6
How do you select multiple columns 'Name' and 'City' to create a new DataFrame?
Question 7
How do you filter rows where the 'Age' column is greater than 30?
df = pd.DataFrame({'Name': ['A', 'B', 'C'], 'Age': [25, 35, 40]})
Question 8
What is the difference between `loc` and `iloc`?
Question 9
Which command selects the first 5 rows of the DataFrame?
Question 10
You want to select rows where 'Age' > 25 AND 'City' is 'London'. Which syntax is correct?
Question 11
What does `df.iloc[0, 1]` return?
Question 12
How do you select rows where the 'Status' column is EITHER 'Active' OR 'Pending'?
Question 13
Which function is used to load data from a CSV file into a DataFrame?
Question 14
You have a CSV file without a header row. How do you read it so the first row isn't treated as columns?
# data.csv contains:
# 1, 2, 3
# 4, 5, 6
Question 15
How can you read only a specific subset of columns (e.g., 'Name' and 'ID') from a large CSV?
Question 16
Which parameter in `read_csv` handles parsing dates automatically?
Question 17
What does `index_col=0` do when reading a CSV?
Question 18
Can Pandas read data directly from a JSON string?
Question 19
Which method gives a quick summary of statistics (count, mean, std, min, max) for numeric columns?
Question 20
How do you calculate the mean of the 'Salary' column?
Question 21
What does `df.corr()` compute?
Question 22
You want to find the unique values in the 'Department' column. Which method should you use?
Question 23
How do you count the occurrences of each unique value in a column?
Question 24
What is the result of `df.max(axis=1)`?
Question 25
Which method returns a boolean DataFrame indicating where values are missing (NaN)?
Question 26
How do you drop all rows that contain at least one missing value?
Question 27
You want to replace all NaN values in the 'Age' column with the average age. Which code works?
mean_age = df['Age'].mean()
Question 28
What does `df.dropna(how='all')` do?
Question 29
Can Pandas distinguish between missing numeric data (NaN) and missing object data (None)?
Question 30
What happens if you calculate the sum of a column containing NaNs?
Question 31
How do you check the data types of all columns in a DataFrame?
Question 32
You have a column 'Price' with string values like '$100'. How do you convert it to numeric?
df = pd.DataFrame({'Price': ['$100', '$200']})
Question 33
What is the dtype 'object' usually used for in Pandas?
Question 34
How do you convert a column 'ID' from float to integer?
df = pd.DataFrame({'ID': [1.0, 2.0, 3.0]})
Question 35
Why might a column of integers become floats automatically?
