Python Libraries - NumPy, Pandas, Matplotlib, SciPy - Question Bank

1. What is the primary data structure in NumPy?
A) List
B) Dictionary
C) ndarray
D) DataFrame
2. The `scipy.sparse` module is designed for:
A) Handling dense matrices efficiently
B) Handling matrices with a large proportion of zero elements
C) Performing complex Fourier transforms
D) Optimizing numerical integration routines
3. Which Matplotlib function allows you to create subplots within a figure?
A) plt.figure()
B) plt.subplot()
C) plt.axes()
D) plt.subplots()
4. What is the default behavior of `df.drop()` if `axis` is not specified?
A) Drops columns
B) Drops rows
C) Drops elements
D) Raises an error
5. Which NumPy function returns the cumulative sum of elements along a given axis?
A) np.sum()
B) np.cumsum()
C) np.cumprod()
D) np.diff()
6. What does `scipy.integrate.quad()` do?
A) Performs numerical integration of a function
B) Solves ordinary differential equations
C) Finds the root of a function
D) Performs numerical differentiation
7. To create a pie chart in Matplotlib, you would use:
A) plt.pie()
B) plt.bar()
C) plt.plot()
D) plt.scatter()
8. Which Pandas method is used to combine two or more Series or DataFrames along a particular axis?
A) merge()
B) join()
C) concat()
D) append()
9. What is the primary purpose of `np.linalg.solve(a, b)`?
A) To compute the determinant of matrix `a`
B) To compute the inverse of matrix `a`
C) To solve the linear matrix equation `ax = b`
D) To compute the eigenvalues of matrix `a`
10. The `scipy.ndimage` module provides functions for:
A) Numerical differentiation
B) Image processing on n-dimensional arrays
C) Interpolation on grids
D) Solving ordinary differential equations
11. Which Matplotlib object represents the entire figure, including all axes, titles, and legends?
A) Axes
B) Artist
C) Figure
D) Canvas
12. What does `df.apply()` in Pandas do?
A) Applies a function along an axis of the DataFrame
B) Applies a function to each element individually
C) Applies a function to a specific column
D) Applies a function to filter the DataFrame
13. Which NumPy function generates an array of random numbers from a uniform distribution?
A) np.random.randn()
B) np.random.randint()
C) np.random.rand()
D) np.random.normal()
14. What is the difference between `np.where(condition)` and `pd.Series.where(condition)`?
A) np.where() returns indices where the condition is true, while Series.where() returns elements where the condition is true and NaN otherwise.
B) np.where() returns elements where the condition is true, while Series.where() returns indices.
C) They perform the exact same function.
D) np.where() is for 1D arrays only, while Series.where() is for DataFrames.
15. The `scipy.spatial` module contains functions for:
A) Image analysis
B) Spatial data structures and algorithms (e.g., KDTree, distance calculations)
C) Time series analysis
D) Network analysis
16. Which Matplotlib function adds a legend to a plot?
A) plt.legend()
B) plt.label()
C) plt.info()
D) plt.show()
17. What is the primary function of the `pivot_table()` method in Pandas?
A) To reshape data from a long format to a wide format, aggregating values
B) To merge two DataFrames
C) To filter rows based on conditions
D) To calculate descriptive statistics
18. Which NumPy function creates an array by repeating elements of an existing array?
A) np.repeat()
B) np.tile()
C) np.copy()
D) np.broadcast()
19. In SciPy, what does the `scipy.fftpack` module provide?
A) Fast Fourier Transforms
B) Fast Walsh-Hadamard Transforms
C) Wavelet Transforms
D) All of the above
20. To create a bar chart in Matplotlib, you would typically use:
A) plt.plot()
B) plt.bar()
C) plt.scatter()
D) plt.hist()
21. Which Pandas method is used to handle missing values (NaN)?
A) df.dropna()
B) df.fillna()
C) df.isnull()
D) All of the above
22. What is the result of `np.mean(array, axis=1)` for a 2D NumPy array?
A) The mean of all elements in the array
B) The mean of each column
C) The mean of each row
D) The standard deviation of each row
23. The `scipy.interpolate` module is used for:
A) Solving systems of linear equations
B) Fitting curves and surfaces to data points
C) Performing statistical hypothesis testing
D) Generating random numbers
24. Which Matplotlib function is used to add labels to the x and y axes?
A) plt.label()
B) plt.axes()
C) plt.xlabel() and plt.ylabel()
D) plt.title()
25. What is the purpose of the `merge()` function in Pandas?
A) To combine DataFrames based on common columns or indices, similar to SQL joins
B) To concatenate DataFrames along an axis
C) To group data by category
D) To fill missing values
26. Which NumPy function creates an array with a specified data type?
A) np.astype()
B) np.dtype()
C) np.create()
D) np.type()
27. What is the fundamental difference between `np.array()` and `pd.Series()`?
A) np.array() creates multi-dimensional arrays, while pd.Series() creates one-dimensional labeled arrays.
B) np.array() is for numerical data only, while pd.Series() can handle mixed types.
C) pd.Series() has an index associated with each element, while np.array() does not.
D) There is no fundamental difference.
28. Which SciPy submodule is used for signal processing tasks like filtering and spectral analysis?
A) scipy.signal
B) scipy.ndimage
C) scipy.fft
D) scipy.sparse
29. To create a scatter plot in Matplotlib, you would typically use:
A) plt.plot()
B) plt.scatter()
C) plt.bar()
D) plt.hist()
30. What does `df.groupby()` in Pandas do?
A) Removes duplicate rows
B) Combines two DataFrames
C) Splits data into groups based on some criteria, applies a function, and combines the results
D) Sorts the DataFrame
31. Which NumPy function allows you to reshape an array without changing its data?
A) np.resize()
B) np.flatten()
C) np.ravel()
D) np.reshape()
32. The `scipy.linalg` module is primarily used for operations related to:
A) Statistics
B) Optimization
C) Linear algebra
D) Interpolation
33. To create a histogram in Matplotlib, which function is typically used?
A) plt.bar()
B) plt.hist()
C) plt.pie()
D) plt.boxplot()
34. Which Pandas method is used to select rows based on a condition?
A) df.loc[]
B) df.iloc[]
C) df.query()
D) All of the above
35. What is the result of `np.dot(a, b)` when `a` and `b` are 1D NumPy arrays?
A) Element-wise multiplication
B) Matrix multiplication
C) Dot product of the two arrays
D) Concatenation of the arrays
36. In SciPy, what is the primary use of the `scipy.optimize` submodule?
A) Solving differential equations
B) Finding roots of functions and minimizing/maximizing functions
C) Performing Fourier transforms
D) Image processing
37. Which Matplotlib function is used to display a plot?
A) plt.save()
B) plt.show()
C) plt.render()
D) plt.display()
38. What does the `inplace=True` argument in Pandas methods do?
A) Returns a new DataFrame with the changes
B) Modifies the DataFrame directly without returning a new one
C) Saves the changes to a file
D) Discards the changes
39. Which NumPy function generates an array with evenly spaced values within a given interval?
A) np.linspace()
B) np.arange()
C) np.logspace()
D) np.geomspace()
40. How do you create a Pandas Series from a Python list?
A) pd.DataFrame(list)
B) pd.Series(list)
C) pd.array(list)
D) pd.Index(list)
41. The `scipy.stats` module provides functions for what purpose?
A) Linear algebra
B) Signal processing
C) Statistical distributions and tests
D) Optimization algorithms
42. Which Matplotlib function adds a title to a plot?
A) plt.xlabel()
B) plt.ylabel()
C) plt.title()
D) plt.legend()
43. What is the purpose of the `read_csv()` function in Pandas?
A) To write data to a CSV file
B) To read data from a CSV file into a DataFrame
C) To merge multiple CSV files
D) To filter data in a CSV file
44. Which NumPy attribute returns the dimensions of an array?
A) array.size
B) array.shape
C) array.ndim
D) array.dtype
45. What does the `axis=0` parameter typically represent in a Pandas DataFrame operation?
A) Operations along columns
B) Operations along rows
C) Operations along diagonals
D) Operations on individual elements
46. In SciPy, which submodule is used for integration?
A) scipy.optimize
B) scipy.integrate
C) scipy.linalg
D) scipy.stats
47. Which Matplotlib function is commonly used to create a line plot?
A) plt.scatter()
B) plt.bar()
C) plt.plot()
D) plt.hist()
48. What is the primary data structure in Pandas used for data manipulation and analysis?
A) Series
B) DataFrame
C) Panel
D) Index
49. Which NumPy function is used to create an array of zeros?
A) np.ones()
B) np.zeros()
C) np.empty()
D) np.arange()