DA Data Analysis Tools and Programming 2 — Questions and Answers
Question 1: What is the purpose of the pandas groupby() function?
- Sorting a DataFrame by column values
- Splitting data into groups and applying aggregate functions to each group (Correct answer)
- Merging two DataFrames
- Filtering rows by condition
Correct answer: Splitting data into groups and applying aggregate functions to each group
groupby() splits a DataFrame into groups based on one or more columns, then applies an aggregation function like sum or mean to each group.
Question 2: In Python, what does the NumPy function np.mean() calculate?
- Median value of an array
- Arithmetic mean of array elements (Correct answer)
- Most frequently occurring value
- Range of the array
Correct answer: Arithmetic mean of array elements
np.mean() computes the arithmetic mean (average) of the elements in a NumPy array or along a specified axis.
Question 3: What is a Jupyter Notebook primarily used for?
- Database administration
- Interactive data exploration combining code, output, and narrative text (Correct answer)
- Version control of Python projects
- Deploying machine learning models to production
Correct answer: Interactive data exploration combining code, output, and narrative text
Jupyter Notebooks allow analysts to write and run code in cells while embedding visualizations and explanatory text in a single document.
Question 4: What Excel function counts cells that meet a specific condition?
- SUMIF
- AVERAGEIF
- COUNTIF (Correct answer)
- IFERROR
Correct answer: COUNTIF
COUNTIF counts the number of cells in a range that satisfy a given condition, such as counting all values above a threshold.
Question 5: What does df.isnull().sum() return in pandas?
- Total number of rows in the DataFrame
- Number of missing values per column (Correct answer)
- Sum of all numeric values
- Boolean mask of duplicate rows
Correct answer: Number of missing values per column
df.isnull().sum() counts the number of NaN (missing) values in each column of the DataFrame.
Question 6: What is the purpose of the pd.merge() function in pandas?
- Concatenate rows from two DataFrames
- Combine two DataFrames based on a common key column, similar to a SQL JOIN (Correct answer)
- Remove duplicate rows
- Reshape a DataFrame from wide to long format
Correct answer: Combine two DataFrames based on a common key column, similar to a SQL JOIN
pd.merge() joins two DataFrames on one or more key columns, supporting inner, left, right, and outer joins.
What is the purpose of the pandas groupby() function?