














































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A practice exam for the python for data science and ai certification. It includes multiple-choice questions covering various python concepts, data structures, and libraries such as numpy and pandas. Each question is followed by a correct answer and a brief explanation. This practice exam is designed to help individuals prepare for the certification and test their knowledge of python in the context of data science and artificial intelligence. The questions cover topics such as data types, operators, loops, functions, exceptions, regular expressions, and file handling. Additionally, it tests knowledge of numpy arrays, pandas dataframes, and matplotlib for data visualization. This resource is valuable for students and professionals looking to enhance their skills in python for data science and ai.
Typology: Exams
1 / 86
This page cannot be seen from the preview
Don't miss anything!















































































Question 1. Which Python data type is immutable? A) list B) dict C) tuple D) set Answer: C Explanation: Tuples cannot be modified after creation, unlike lists, dicts, and sets which are mutable. Question 2. What is the output of len("DataScience")? A) 10 B) 11 C) 12 D) 13 Answer: B Explanation: The string “DataScience” contains 11 characters, so len returns 11. Question 3. Which operator has the highest precedence in Python? A) or B) and C) not D) == Answer: C Explanation: Unary not is evaluated before the binary logical operators and and or.
Question 4. In a for loop, which statement correctly iterates over the keys of a dictionary d? A) for k in d.values(): B) for k in d.items(): C) for k in d: D) for k in d.keys(): Answer: C Explanation: Iterating directly over a dictionary yields its keys. Question 5. What does the global keyword do inside a function? A) Declares a variable as constant B) Allows modification of a variable defined outside the function C) Imports a module globally D) Creates a new global variable automatically Answer: B Explanation: global tells Python to use the variable from the module’s global scope, enabling assignment. Question 6. Which of the following is a correct lambda expression that adds two numbers? A) lambda x, y: x + y B) lambda (x, y): x + y C) lambda x y: x + y D) lambda x; y: x + y Answer: A Explanation: The syntax lambda arguments: expression requires commas between parameters.
Question 10. Which slicing expression returns the last three elements of a list L? A) L[-3:] B) L[:3] C) L[-3] D) L[3:] Answer: A Explanation: Negative start index counts from the end; -3: selects the last three items. Question 11. How do you create a set containing the numbers 1, 2, and 3? A) {1, 2, 3} B) [1, 2, 3] C) (1, 2, 3) D) set(1,2,3) Answer: A Explanation: Curly braces with comma‑separated values define a set literal. Question 12. Which string method checks if all characters are alphabetic? A) isalpha() B) isalnum() C) isdigit() D) isnumeric() Answer: A Explanation: isalpha() returns True only when every character is a letter. Question 13. What does the regular expression r'\d{3}-\d{2}-\d{4}' match?
A) A date in YYYY‑MM‑DD format B) An email address C) A US Social Security Number D) A phone number Answer: C Explanation: It matches three digits, a hyphen, two digits, a hyphen, and four digits – the SSN pattern. Question 14. Which import statement correctly imports the sqrt function from the math module? A) import math.sqrt B) from math import sqrt C) import sqrt from math D) import math.sqrt as sqrt Answer: B Explanation: from module import name imports a specific attribute. Question 15. In a Jupyter notebook, which magic command lists all variables in the current namespace? A) %who B) %list C) %vars D) %env Answer: A Explanation: %who displays user‑defined variables.
Question 19. What does arr.dtype return for arr = np.array([1, 2, 3])? A) int64 (or platform‑specific integer) B) float64 C) object D) bool Answer: A Explanation: The array consists of Python ints, which NumPy stores as an integer dtype (commonly int64). Question 20. Which operation performs element‑wise multiplication of two NumPy arrays a and b? A) a @ b B) np.dot(a, b) C) a * b D) np.multiply(a, b, out=None) Answer: C Explanation: The * operator is overloaded for element‑wise multiplication; np.multiply does the same but * is simpler. Question 21. What broadcasting rule allows adding a 1‑D array of shape (3,) to a 2‑D array of shape (5,3)? A) The 1‑D array is automatically reshaped to (1,3) and then broadcast to (5,3) B) Broadcasting is not allowed; a ValueError is raised C) The 2‑D array is reshaped to (5,1) D) Both arrays are flattened before addition Answer: A
Explanation: NumPy expands the smaller dimension (adds a leading 1) and repeats it across the larger dimension. Question 22. Which NumPy function computes the inverse of a square matrix M? A) np.det(M) B) np.linalg.inv(M) C) np.linalg.solve(M, I) D) np.inverse(M) Answer: B Explanation: np.linalg.inv returns the matrix inverse. Question 23. What does np.where(arr > 0, 1, - 1) return? A) An array with 1 where arr is positive and - 1 elsewhere B) Indices of positive elements C) A boolean mask of positive elements D) A tuple of two arrays Answer: A Explanation: np.where(condition, x, y) selects x where condition is true, otherwise y. Question 24. Which Pandas object is a one‑dimensional labeled array? A) DataFrame B) Series C) Panel D) Index Answer: B
Explanation: loc works with boolean masks based on column values. Question 28. Which Pandas function drops rows containing any missing values? A) df.fillna() B) df.dropna() C) df.isnull() D) df.replace() Answer: B Explanation: dropna() removes rows (or columns) with NaNs. Question 29. What does df['salary'].mean() compute? A) Median salary B) Sum of salaries C) Average (arithmetic mean) of the salary column D) Standard deviation of salaries Answer: C Explanation: .mean() returns the arithmetic average. Question 30. Which method adds a new column dept with the same value 'HR' for all rows? A) df.append('HR') B) df['dept'] = 'HR' C) df.assign(dept='HR') D) Both B and C are correct Answer: D
Explanation: Direct assignment and assign both create/overwrite a column with a scalar value. Question 31. How can you merge df1 and df2 on a common column id using an inner join? A) pd.concat([df1, df2], on='id') B) df1.merge(df2, how='inner', on='id') C) df1.join(df2, on='id') D) pd.merge(df1, df2, how='outer', on='id') Answer: B Explanation: DataFrame.merge with how='inner' performs an inner join on the specified key. Question 32. Which Pandas operation reshapes a DataFrame from long to wide format? A) pivot() B) melt() C) stack() D) unstack() Answer: A Explanation: pivot creates a wide format by specifying index, columns, and values. Question 33. What does df.groupby('city').agg({'sales':'sum'}) return? A) Total sales per city B) Average sales per city C) Count of rows per city D) Median sales per city Answer: A
Question 37. What does the plt.subplots() function return? A) A single Axes object B) A Figure object only C) A tuple containing a Figure and an Axes (or array of Axes) D) Nothing; it only creates a new figure Answer: C Explanation: subplots creates a Figure and one or more Axes and returns them as a tuple. Question 38. Which plot type is most appropriate for visualizing the relationship between two continuous variables? A) Bar plot B) Histogram C) Scatter plot D) Pie chart Answer: C Explanation: Scatter plots display paired numeric values, revealing correlation patterns. Question 39. In Seaborn, which function creates a pairwise relationship grid for a DataFrame df? A) sns.pairplot(df) B) sns.jointplot(df) C) sns.heatmap(df) D) sns.lmplot(df) Answer: A Explanation: pairplot draws scatter plots (and histograms) for each pair of variables.
Question 40. Which of the following is a principle of effective data visualization? A) Use as many colors as possible to make the chart vibrant B) Hide axis labels to reduce clutter C) Choose a chart type that matches the data’s nature and the story you want to tell D) Always use 3‑D effects for added depth Answer: C Explanation: Selecting an appropriate visual form ensures clarity and accurate interpretation. Question 41. In Scikit‑learn, which class implements a linear regression model? A) LogisticRegression B) LinearRegression C) Ridge D) SVR Answer: B Explanation: LinearRegression fits a linear model using ordinary least squares. Question 42. What does the fit method do in a Scikit‑learn estimator? A) Predicts target values for new data B) Splits data into training and test sets C) Learns model parameters from the training data D) Evaluates model performance on a validation set Answer: C Explanation: fit trains the estimator by estimating its parameters from the provided data.
Question 46. Which encoding technique creates a binary column for each category value? A) Label Encoding B) One‑Hot Encoding C) Ordinal Encoding D) Frequency Encoding Answer: B Explanation: One‑Hot Encoding expands a categorical variable into separate binary columns. Question 47. In K‑Nearest Neighbors classification, which parameter controls the number of neighbors considered? A) weights B) n_neighbors C) algorithm D) leaf_size Answer: B Explanation: n_neighbors specifies how many nearest points vote for the class. Question 48. Which Scikit‑learn class implements a decision tree classifier? A) DecisionTreeRegressor B) RandomForestClassifier C) DecisionTreeClassifier D) AdaBoostClassifier Answer: C Explanation: DecisionTreeClassifier builds a tree for categorical target variables.
Question 49. What does a confusion matrix’s “False Positive” represent? A) Correctly predicted positive cases B) Actual positives incorrectly predicted as negative C) Actual negatives incorrectly predicted as positive D) Incorrectly predicted negatives that are actually positives Answer: C Explanation: A false positive occurs when the model predicts the positive class for a negative instance. Question 50. Which Scikit‑learn utility performs K‑Fold cross‑validation? A) cross_val_predict B) KFold C) StratifiedShuffleSplit D) LeaveOneOut Answer: B Explanation: KFold creates K equally sized folds for cross‑validation. Question 51. What is the purpose of GridSearchCV? A) To perform dimensionality reduction B) To automatically select the best hyper‑parameter combination using cross‑validation C) To visualize decision boundaries D) To split data into train and test sets Answer: B Explanation: GridSearchCV exhaustively searches over a parameter grid and evaluates each setting via CV.
Question 55. How do you convert a column of timestamps df['date'] to Pandas datetime objects? A) pd.to_datetime(df['date']) B) df['date'].astype(datetime) C) datetime(df['date']) D) df['date'].convert() Answer: A Explanation: pd.to_datetime parses strings or other formats into datetime64[ns]. Question 56. Which Pandas method resamples a time series to compute the monthly mean? A) df.resample('M').mean() B) df.groupby('month').mean() C) df.rolling('30D').mean() D) df.shift(30).mean() Answer: A Explanation: resample('M') groups data by month frequency, then .mean() aggregates. Question 57. What does the rolling(window=3).sum() operation compute? A) Cumulative sum of the entire series B) Sum of every three consecutive elements, sliding by one each step C) Sum of elements at positions that are multiples of three D) Sum of the first three elements only Answer: B Explanation: Rolling windows compute the function over a moving window of the specified size.
Question 58. Which activation function outputs values between 0 and 1 and is commonly used for binary classification outputs? A) ReLU B) Tanh C) Sigmoid D) Softmax Answer: C Explanation: The sigmoid function squashes inputs to the (0,1) interval, suitable for probabilities. Question 59. In a feed‑forward neural network, what is the role of the hidden layer? A) Directly produce the final output B) Store the input data unchanged C) Learn intermediate representations that capture complex patterns D) Perform back‑propagation only Answer: C Explanation: Hidden layers transform inputs through learned weights, enabling the network to model non‑linear relationships. Question 60. Which library provides the requests.get() function for making HTTP GET requests? A) urllib B) http.client C) requests D) socket