0% found this document useful (0 votes)
27 views16 pages

Data Science 150 MCQ

The document contains a series of multiple-choice questions related to NumPy and Pandas, covering topics such as array creation, data manipulation, and essential functions. It tests knowledge on importing libraries, array operations, DataFrame methods, and data analysis techniques. The questions are designed to assess understanding of these two popular Python libraries used for numerical and data analysis.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views16 pages

Data Science 150 MCQ

The document contains a series of multiple-choice questions related to NumPy and Pandas, covering topics such as array creation, data manipulation, and essential functions. It tests knowledge on importing libraries, array operations, DataFrame methods, and data analysis techniques. The questions are designed to assess understanding of these two popular Python libraries used for numerical and data analysis.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 16

1. What does NumPy stand for?

a) Number Python
b) Numeric Python
c) Numerical Python
d) Numbers Package

2. Which of the following is the correct way to import NumPy?


a) import numpy
b) import numpy as np
c) import np as numpy
d) from numpy import np

3. Which function is used to create a NumPy array?


a) array()
b) list()
c) np.array()
d) np.list()

4. NumPy arrays are:


a) Immutable
b) Mutable
c) Only 1D
d) Only used for strings

5. Which function is used to get the shape of a NumPy array?


a) shape()
b) np.shape()
c) array.shape
d) size()

6. What is the output of np.zeros((2,3))?


a) A 2x3 array filled with 0s
b) A 2x3 array filled with 1s
c) A 3x2 array filled with 0s
d) An empty array

7. What does np.ones(5) return?


a) Array of 0s
b) Array of 5 ones
c) Scalar value 5
d) Error

8. The function to create an array with evenly spaced values is:


a) np.linspace()
b) np.even()
c) np.arange()
d) np.range()

9. What is the difference between arange() and linspace()?


a) arange() allows step size
b) linspace() allows step size
c) Both are the same
d) arange() returns float values by default

10. Which attribute shows the number of elements in an array?


a) size
b) shape
c) ndim
d) len

---

11. What will a[0] return if a = np.array([10, 20, 30])?


a) 10
b) 20
c) 30
d) Error

12. How to access the last element of a 1D array?


a) a[-1]
b) a[0]
c) a[1]
d) a[2]

13. Slicing a[1:3] returns:


a) Elements at index 1 and 2
b) Elements at index 1 and 3
c) Index 0 to 3
d) Only index 3

14. What will a[:,1] do on a 2D array?


a) Return second row
b) Return second column
c) Return first column
d) Error

15. Which of these allows reshaping a 1D array into 2D?


a) reshape()
b) resize()
c) array()
d) convert()

16. What does a[1:, :2] do?


a) Skips first row, selects first 2 columns
b) Skips first column, selects first 2 rows
c) Selects all rows and columns
d) Returns error

17. What does ndim return?


a) Shape
b) Number of rows
c) Number of dimensions
d) Size of memory

18. Which method flattens a NumPy array?


a) flatten()
b) squeeze()
c) ravel()
d) reshape(-1)

19. To reverse an array, use:


a) [::-1]
b) [1:0]
c) reverse()
d) flip()

20. What is the result of a[::2]?


a) Even indices
b) Odd indices
c) Last two values
d) None

---

21. What is broadcasting in NumPy?


a) Sharing arrays across networks
b) Resizing mismatched shapes
c) Performing operations between different shapes
d) Copying arrays

22. What happens when you add two arrays of same shape?
a) Concatenation
b) Element-wise addition
c) Merging
d) Error

23. Which function performs matrix multiplication?


a) np.multiply()
b) np.matmul()
c) np.multiplication()
d) np.dotarray()

24. Which operator is used for element-wise multiplication?


a)
b) @
c) /
d) //

25. How do you find the maximum value in a NumPy array?


a) array.max()
b) np.maximum()
c) np.max(array)
d) Both a and c

26. What does np.mean() return?


a) Mode
b) Average
c) Median
d) Standard Deviation

27. Which function is used for standard deviation?


a) std()
b) np.std()
c) deviation()
d) average()

28. How to get the index of the max element in array?


a) argmax()
b) maxindex()
c) indexmax()
d) getmax()
29. What does np.sort(array) do?
a) Sorts in-place
b) Sorts and returns new array
c) Returns max value
d) Deletes duplicates

30. What does np.cumsum(array) return?


a) Cumulative product
b) Sorted array
c) Cumulative sum
d) Mean

---

31. Which function returns identity matrix?


a) np.identity()
b) np.eye()
c) np.unit()
d) np.id()

32. What does np.diag() return?


a) Diagonal line
b) Diagonal elements
c) Anti-diagonal
d) Matrix transpose

33. Which function is used to generate random floats?


a) np.random.rand()
b) np.random.randint()
c) np.rand()
d) np.float.rand()

34. What does np.random.randint(1, 5, size=3) return?


a) 3 floats
b) 3 ints from 1 to 4
c) 3 ints from 1 to 5
d) Error

35. How to generate a 3x3 matrix of random numbers between 0 and 1?


a) np.random.rand(3,3)
b) np.rand(3,3)
c) np.random.random((3,3))
d) Both a and c

36. What does np.unique(array) return?


a) Maximum values
b) Unique elements
c) Sum
d) Random values

37. Which function shuffles elements in place?


a) np.shuffle()
b) np.random.shuffle()
c) np.shuffle.array()
d) array.shuffle()
38. What does np.copy(array) do?
a) Creates shallow copy
b) Creates reference
c) Creates deep copy
d) Deletes array

39. Which method converts boolean array to integers?


a) astype(int)
b) boolToInt()
c) convert()
d) toint()

40. How to convert 1D array to 2D row vector?


a) reshape(1, -1)
b) reshape(-1, 1)
c) np.row(array)
d) np.expand(array)

---

41. What is np.isnan() used for?


a) To detect NaN values
b) To detect integers
c) To sort
d) To replace nulls

42. How to replace NaN values with 0?


a) np.nan_to_num(array)
b) replace.nan(0)
c) array.fillna(0)
d) np.replace(array, 0)

43. What does array[array > 5] return?


a) Boolean array
b) Indexes
c) Filtered elements
d) None

44. Which function returns the indices where condition is True?


a) where()
b) iftrue()
c) np.where()
d) np.locate()

45. What is the result of array.any()?


a) Sum
b) True if any element is True
c) Mean
d) Minimum

46. What is the result of array.all()?


a) True if all elements are True
b) False if one is False
c) Checks dtype
d) Returns sum

47. How to vertically stack two arrays?


a) np.vstack()
b) np.concat()
c) np.vstacked()
d) np.stackv()

48. How to horizontally stack two arrays?


a) np.hstack()
b) np.append()
c) np.add()
d) np.side_stack()

49. Which method joins arrays along a new axis?


a) np.concatenate()
b) np.join()
c) np.stack()
d) np.link()

50. What does np.split(array, 2) do?


a) Splits into 2 parts
b) Removes half
c) Duplicates
d) Returns a boolean

1. What is Pandas mainly used for?


a) Web development
b) Image processing
c) Data manipulation and analysis
d) Game development

2. Which of the following is correct for importing Pandas?


a) import pandas
b) import pandas as pd
c) import pd
d) include pandas

3. Which data structure does Pandas use for 1D labeled data?


a) Array
b) Series
c) List
d) DataFrame

4. What is a DataFrame in Pandas?


a) One-dimensional data
b) Two-dimensional labeled data structure
c) Matrix
d) JSON object

5. What is the default axis for rows in Pandas?


a) 1
b) 0
c) -1
d) 2

6. Which method is used to read a CSV file into Pandas?


a) pd.load_csv()
b) pd.read_csv()
c) pd.open_csv()
d) pd.csv()
7. Which method shows the first 5 rows of a DataFrame?
a) first()
b) peek()
c) head()
d) top()

8. Which method returns the last n rows of a DataFrame?


a) tail()
b) last()
c) bottom()
d) foot()

9. Which attribute gives the number of rows and columns in a DataFrame?


a) pd.count()
b) shape
c) size
d) dimension

10. What does df.info() provide?


a) Statistical summary
b) Data types and non-null values
c) Graph
d) Memory usage only

---

11. How can we select a column from a DataFrame?


a) df(column)
b) df.column
c) df['column']
d) Both b and c

12. Which method selects rows by index labels?


a) iloc
b) loc
c) label
d) row

13. Which method selects rows by integer position?


a) iloc
b) loc
c) index
d) slice

14. What does df[0:3] return?


a) Columns 0 to 3
b) Rows 0 to 2
c) Last 3 rows
d) Error

15. What does df.iloc[:, 1] return?


a) First row
b) Second column
c) First column
d) Last row
16. How to filter rows where column A > 10?
a) df.where(A > 10)
b) df(df.A > 10)
c) df[df['A'] > 10]
d) df.select(A > 10)

17. Which method can reset the index of a DataFrame?


a) df.reset_index()
b) df.drop_index()
c) df.remove_index()
d) df.clear_index()

18. Which method sets a column as index?


a) df.index('col')
b) df.set_index('col')
c) df.assign_index('col')
d) df.column_index('col')

19. What does df.at[2, 'A'] do?


a) Returns cell at row 2, column A
b) Returns column A
c) Returns row 2
d) Nothing

20. Which method is fastest for accessing a scalar value?


a) loc
b) iloc
c) at
d) iat

---

21. Which method removes missing values?


a) df.delete_na()
b) df.dropna()
c) df.remove_na()
d) df.clean()

22. Which method replaces missing values?


a) df.fillna()
b) df.fixna()
c) df.replace_na()
d) df.replacena()

23. What does df.isnull() return?


a) Count of null values
b) DataFrame with True where null
c) Error
d) List of nulls

24. Which method changes the data type of a column?


a) astype()
b) dtype()
c) set_type()
d) change_type()

25. How to rename a column?


a) df.rename()
b) df.rename(columns={'old':'new'})
c) df.columns = []
d) df.change_name()

26. Which method drops a column?


a) df.remove()
b) df.delete()
c) df.drop('col', axis=1)
d) df.erase()

27. What is the use of df.duplicated()?


a) Shows null values
b) Detects duplicate rows
c) Deletes duplicates
d) Sorts data

28. How to replace values in a DataFrame?


a) df.swap()
b) df.replace()
c) df.rename()
d) df.change()

29. How to convert column to datetime?


a) pd.datetime(df['col'])
b) pd.to_datetime(df['col'])
c) df.date_time()
d) df.strtotime()

30. Which function merges two DataFrames by key?


a) combine()
b) add()
c) merge()
d) mix()

---

31. What does df.groupby('col') do?


a) Sorts DataFrame
b) Groups data by unique values
c) Filters nulls
d) Merges DataFrames

32. What is aggregation in Pandas?


a) Compressing rows
b) Summarizing data
c) Sorting
d) Merging

33. Which function sorts a DataFrame?


a) df.sort()
b) df.sort_values()
c) df.sortby()
d) df.order()

34. How to sort DataFrame by index?


a) df.sort_index()
b) df.sort()
c) df.index_sort()
d) df.sort_row()

35. Which method returns summary statistics?


a) summary()
b) df.stats()
c) df.describe()
d) df.summary()

36. What does df['A'].mean() return?


a) Total sum
b) Maximum value
c) Average
d) Null count

37. Which of these shows the correlation matrix?


a) df.corr()
b) df.relation()
c) df.correlation()
d) df.connect()

38. What does df.nunique() return?


a) Total rows
b) Unique values per column
c) Column names
d) Duplicates

39. Which method shows value frequency in a column?


a) df.value_count()
b) df.count_values()
c) df['col'].value_counts()
d) df.frequency()

40. Which method gives cumulative sum?


a) df.cumsum()
b) df.sum()
c) df.cum()
d) df.addsum()

---

41. Which method pivots a DataFrame?


a) df.transpose()
b) df.pivot()
c) df.melt()
d) df.pivot_table()

42. What does df.melt() do?


a) Combines columns
b) Converts wide to long format
c) Deletes columns
d) Creates charts

43. Which method concatenates two DataFrames?


a) pd.merge()
b) pd.concat()
c) pd.add()
d) pd.join()

44. How to read Excel files in Pandas?


a) pd.read_xlsx()
b) pd.excel_read()
c) pd.read_excel()
d) pd.open_excel()

45. Which method writes DataFrame to CSV?


a) df.save()
b) df.to_csv()
c) df.write_csv()
d) df.export()

46. Which argument is used to specify index in read_csv()?


a) row_index
b) usecols
c) index_col
d) rowid

47. What does axis=1 mean in Pandas?


a) Row-wise
b) Column-wise
c) Diagonal
d) Element-wise

48. How to transpose a DataFrame?


a) df.reverse()
b) df.T
c) df.transpose()
d) Both b and c

49. What does inplace=True do?


a) Creates new copy
b) Updates original DataFrame
c) Saves to file
d) Shows preview

50. Which method checks if DataFrame is empty?


a) df.null()
b) df.empty()
c) df.isna()
d) df.blank()

1. What is Matplotlib primarily used for?


a) Data storage
b) Data visualization
c) Machine learning
d) Web development

2. Which command is used to import the pyplot module from Matplotlib?


a) import matplotlib.plot as plt
b) import matplotlib.pyplot as plt
c) import plot.pyplot as plt
d) import matplotlib.pyplot

3. Who created Matplotlib?


a) Guido van Rossum
b) John D. Hunter
c) Bjarne Stroustrup
d) Dennis Ritchie

4. Which function is used to display the plot on the screen?


a) plt.display()
b) plt.plot()
c) plt.show()
d) plt.view()

5. What is the default backend used by Matplotlib?


a) Qt5Agg
b) TkAgg
c) WebAgg
d) GTK3Agg

6. Which function is used to create a simple line plot?


a) line()
b) draw()
c) plot()
d) scatter()

7. Which function is used to create a scatter plot?


a) scatter()
b) dot()
c) point()
d) line()

8. Which function is used to create a bar chart?


a) bar()
b) bar_chart()
c) chart()
d) hist()

9. Which function is used to create a histogram?


a) histogram()
b) hist()
c) bar()
d) plot()

10. Which function is used to create a pie chart?


a) pie()
b) chart()
c) circle()
d) plot()

---

11. What does the xlabel() function do in Matplotlib?


a) Sets the x-axis label
b) Sets the y-axis label
c) Sets the plot title
d) Adds a legend

12. What does the ylabel() function do in Matplotlib?


a) Sets the x-axis label
b) Sets the y-axis label
c) Sets the plot title
d) Adds a legend

13. Which function is used to set the title of a plot?


a) set_title()
b) title()
c) plot_title()
d) add_title()

14. Which function is used to add a legend to the plot?


a) legend()
b) add_legend()
c) plot_legend()
d) show_legend()

15. Which function is used to add grid lines to the plot?


a) grid()
b) add_grid()
c) plot_grid()
d) show_grid()

16. Which parameter is used to change the color of a line in a plot?


a) linecolor
b) color
c) col
d) c

17. Which parameter is used to change the line style in a plot?


a) linestyle
b) style
c) line
d) ls

18. Which parameter is used to change the marker style in a plot?


a) marker
b) mark
c) symbol
d) m

19. Which function is used to create a figure in Matplotlib?


a) figure()
b) create_figure()
c) new_figure()
d) plot_figure()

20. Which function is used to create subplots in Matplotlib?


a) subplot()
b) subplots()
c) create_subplot()
d) add_subplot()

---

21. Which function is used to save a figure to a file?


a) savefig()
b) save_plot()
c) exportfig()
d) downloadfig()

22. Which parameter is used to set the figure size in inches?


a) figsize
b) size
c) dimensions
d) fig_dimensions

23. Which parameter is used to set the resolution (dots per inch) of the figure?
a) dpi
b) resolution
c) dots_per_inch
d) res

24. Which function is used to add text annotations to a plot?


a) annotate()
b) add_text()
c) text()
d) add_annotation()

25. Which function is used to set the x-axis ticks?


a) xticks()
b) set_xticks()
c) x_ticks()
d) ticks_x()

26. Which function is used to set the y-axis ticks?


a) yticks()
b) set_yticks()
c) y_ticks()
d) ticks_y()

27. Which function is used to set custom tick labels on the x-axis?
a) xticklabels()
b) set_xticklabels()
c) x_ticklabels()
d) ticks_x_labels()

28. Which function is used to set custom tick labels on the y-axis?
a) yticklabels()
b) set_yticklabels()
c) y_ticklabels()
d) ticks_y_labels()

29. Which function is used to change the font size of plot elements?
a) fontsize
b) font_size
c) set_fontsize()
d) font.size

30. Which function is used to change the font family of plot elements?
a) fontfamily
b) font_family
c) set_fontfamily()
d) font.family

---
31. Which function is used to create a figure and a set of subplots?
a) subplots()
b) subplot()
c) figure()
d) create_subplots()

32. Which function is used to add a subplot to an existing figure?


a) add_subplot()
b) subplot()
c) subplots()
d) create_subplot()

33. Which parameter is used to specify the number of rows and columns in subplots?
a) nrows and ncols
b) rows and cols
c) num_rows and num_cols
d) r and c

34. Which function is used to adjust the spacing between subplots?


a) subplots_adjust()
b) adjust_subplots()
c) set_spacing()
d) spacing()

35. Which function is used to share the x-axis among subplots?


a) sharex=True
b) xshare=True
c) share_x=True
d) x_shared=True

36. Which function is used to share the y-axis among subplots?


a) sharey=True
b) yshare=True
c) share_y=True
d) y_shared=True

37. Which function is used to create multiple plots in one figure?


a) subplots()
b) subplot()
c) multi_plot()
d) plot_multiple()

38. Which function is used to set the aspect ratio of the plot?
a) set_aspect()
b) aspect()
c) set_ratio()
d) ratio()

39. Which function is used to turn off the axes in a plot?


a) axis('off')
b) axes_off()
c) hide_axes()
d) turn_off_axes()

40. Which function is used to turn on the axes in a plot?


a) axis('on')
b) axes_on()
c) show_axes()
d) turn_on_axes()

---

41. Which function is used to create a box plot?


a) boxplot()
b) box_plot()
c) plot_box()
d) create_boxplot()

42. Which function is used to create a heatmap?


a) imshow()
b) heatmap()
c) plot_heatmap()
d) create_heatmap()

43. Which function is used to create an error bar plot?


a) errorbar()
b) plot_error()
c) error_plot()
d) create_errorbar()

44. Which function is used to create a stack plot?


a) stackplot()
b) plot_stack()
c) stack_plot()
d) create_stackplot()

45. Which function is used to create an area plot?


a) fill_between()
b) area_plot()
c) plot_area()
d) \create\_areap

You might also like