Data Science with Python Certification Data Science with Python (Basic) 2 — Questions and Answers
Question 1: Which NumPy function creates an array of evenly spaced values over a specified interval?
- np.arange()
- np.linspace() (Correct answer)
- np.zeros()
- np.ones()
Correct answer: np.linspace()
np.linspace() returns evenly spaced numbers over a specified interval, including both endpoints by default.
Question 2: In pandas, what does the method df.dropna() do by default?
- Drops columns with any missing values
- Drops rows with any missing values (Correct answer)
- Fills missing values with zero
- Removes duplicate rows
Correct answer: Drops rows with any missing values
By default, df.dropna() removes any row that contains at least one NaN value (axis=0).
Question 3: What is the output of np.array([1,2,3]).reshape(3,1).shape?
- (3,)
- (1,3)
- (3,1) (Correct answer)
- (3,3)
Correct answer: (3,1)
reshape(3,1) converts the 1-D array into a 2-D column vector with 3 rows and 1 column, so shape is (3,1).
Question 4: Which pandas method is used to compute summary statistics (mean, std, min, max) for a DataFrame?
- df.info()
- df.head()
- df.describe() (Correct answer)
- df.value_counts()
Correct answer: df.describe()
df.describe() generates descriptive statistics including count, mean, std, min, quartiles, and max for numeric columns.
Question 5: In Matplotlib, which function saves the current figure to a file?
- plt.show()
- plt.save()
- plt.savefig() (Correct answer)
- plt.export()
Correct answer: plt.savefig()
plt.savefig('filename.png') saves the current figure to disk in the specified format.
Question 6: What does the pandas method df.groupby('col').mean() return?
- The mean of the entire DataFrame
- Mean values for each unique group in 'col' (Correct answer)
- The column named 'col' averaged with adjacent columns
- A single scalar mean value
Correct answer: Mean values for each unique group in 'col'
groupby splits the DataFrame by unique values of 'col', then mean() computes the average of all other numeric columns within each group.
Question 7: Which scikit-learn class is used to split data into training and test sets?
- sklearn.model_selection.CrossValidate
- sklearn.model_selection.train_test_split (Correct answer)
- sklearn.preprocessing.split
- sklearn.datasets.train_test
Correct answer: sklearn.model_selection.train_test_split
train_test_split from sklearn.model_selection randomly partitions arrays or matrices into train and test subsets.
Which NumPy function creates an array of evenly spaced values over a specified interval?