Home »
MCQs
Python Data Analysis MCQs (Multiple-Choice Questions)
Python provides powerful libraries for data analysis, with pandas being one of the most widely used tools for working with structured and tabular data. It provides data structures such as Series and DataFrame along with functions for data cleaning, transformation, analysis, grouping, merging, and visualization.
Python Data Analysis MCQs
These Python Data Analysis MCQs cover important concepts related to pandas, NumPy, DataFrame, Series, data cleaning, missing values, filtering, sorting, grouping, aggregation, merging, reshaping, statistics, and data visualization.
List of Python Data Analysis MCQs
The following Python Data Analysis MCQs are designed to test your understanding of data analysis using Python and its commonly used data-analysis tools.
1. Which Python library is widely used for data analysis and manipulation?
- pandas
- tkinter
- socket
- flask
Answer: A) pandas
Explanation:
pandas is an open-source Python library that provides data structures and tools for practical data analysis and manipulation.
2. Which alias is conventionally used when importing pandas?
- import pandas as pd
- import pandas as ps
- import pandas as p
- import pandas as python
Answer: A) import pandas as pd
Explanation:
The conventional alias for pandas is pd, so it is commonly imported using import pandas as pd.
3. Which two are the primary data structures in pandas?
- List and Tuple
- Series and DataFrame
- Array and Matrix
- Set and Dictionary
Answer: B) Series and DataFrame
Explanation:
Series and DataFrame are the two primary pandas data structures used for most data-analysis tasks.
4. What is a pandas Series?
- A two-dimensional table only
- A one-dimensional labeled array
- A database table
- A Python module
Answer: B) A one-dimensional labeled array
Explanation:
A Series is a one-dimensional labeled data structure that can hold data of different types.
5. What is a pandas DataFrame?
- A two-dimensional labeled data structure
- A one-dimensional array only
- A Python dictionary only
- A database connection
Answer: A) A two-dimensional labeled data structure
Explanation:
A DataFrame is a two-dimensional labeled data structure with rows and columns, commonly used to represent tabular data.
6. Which function can be used to create a DataFrame?
- pd.DataFrame()
- pd.Table()
- pd.CreateFrame()
- pd.DataTable()
Answer: A) pd.DataFrame()
Explanation:
pd.DataFrame() creates a pandas DataFrame from supported data structures such as dictionaries, lists, arrays, and other pandas objects.
7. Which function is commonly used to create a pandas Series?
- pd.Series()
- pd.Array()
- pd.Column()
- pd.Vector()
Answer: A) pd.Series()
Explanation:
pd.Series() creates a one-dimensional labeled pandas Series.
8. Which function is commonly used to read a CSV file into a DataFrame?
- pd.open_csv()
- pd.read_csv()
- pd.load_csv()
- pd.csv_read()
Answer: B) pd.read_csv()
Explanation:
pd.read_csv() reads a comma-separated values file and returns a DataFrame by default.
9. Which method is used to write a DataFrame to a CSV file?
- to_csv()
- write_csv()
- save_csv()
- export_csv()
Answer: A) to_csv()
Explanation:
The to_csv() method writes a DataFrame to a CSV file or another file-like object.
10. Which method displays the first few rows of a DataFrame?
- first()
- head()
- top()
- start()
Answer: B) head()
Explanation:
The head() method returns the first rows of a DataFrame or Series.
11. Which method displays the last few rows of a DataFrame?
- end()
- last()
- tail()
- bottom()
Answer: C) tail()
Explanation:
The tail() method returns the last rows of a DataFrame or Series.
12. Which DataFrame attribute returns the row and column dimensions?
- dimension
- shape
- size_shape
- dimensions_only
Answer: B) shape
Explanation:
The shape attribute returns a tuple containing the number of rows and columns.
13. Which attribute returns the column labels of a DataFrame?
- columns
- fields
- headers
- labels_only
Answer: A) columns
Explanation:
The columns attribute contains the column labels of a DataFrame.
14. Which attribute provides the row labels of a DataFrame?
- rows
- index
- row_labels_only
- indices_data
Answer: B) index
Explanation:
The index attribute represents the row labels of a pandas DataFrame or Series.
15. Which method provides a concise summary of a DataFrame's information?
- info()
- summary()
- details()
- describe_data()
Answer: A) info()
Explanation:
The info() method prints information about the DataFrame, including indexes, columns, data types, and non-null values.
16. Which method provides descriptive statistics for numerical columns by default?
- statistics()
- describe()
- summary()
- stats()
Answer: B) describe()
Explanation:
The describe() method generates descriptive statistics such as count, mean, standard deviation, minimum, and maximum.
17. Which method is commonly used to detect missing values in a DataFrame?
- isna()
- missing()
- findna()
- hasnull()
Answer: A) isna()
Explanation:
isna() detects missing values and returns a boolean result for each element.
18. Which function is an alias for detecting missing values in pandas?
- pd.isnull()
- pd.nullcheck()
- pd.missing()
- pd.checknull()
Answer: A) pd.isnull()
Explanation:
isnull() is an alias for isna() in pandas.
19. Which method can remove rows containing missing values?
- remove_na()
- dropna()
- delete_na()
- clearna()
Answer: B) dropna()
Explanation:
The dropna() method can remove rows or columns containing missing values, depending on its parameters.
20. Which method can replace missing values with a specified value?
- fillna()
- replace_na()
- setna()
- insertna()
Answer: A) fillna()
Explanation:
The fillna() method is used to fill missing values with specified values or other supported filling strategies.
21. Which method sorts a DataFrame by the values of one or more columns?
- sort_values()
- order_by()
- sort_columns()
- arrange()
Answer: A) sort_values()
Explanation:
The sort_values() method sorts a DataFrame according to specified column or index values.
22. Which method sorts a DataFrame based on its index?
- sort_index()
- index_sort()
- sort_rows()
- order_index()
Answer: A) sort_index()
Explanation:
The sort_index() method sorts the DataFrame or Series by its index labels.
23. Which method is used to group data in pandas?
- groupby()
- group_data()
- group_rows()
- categorize()
Answer: A) groupby()
Explanation:
The groupby() operation follows the split-apply-combine approach and is used to perform operations separately on groups of data.
24. Which operation is part of the split-apply-combine approach used by pandas groupby?
- Split the data into groups
- Compile the Python interpreter
- Encrypt the DataFrame
- Convert all values to strings
Answer: A) Split the data into groups
Explanation:
A groupby operation involves splitting data into groups, applying a function to each group, and combining the results.
25. Which function can calculate the average of values in a pandas Series?
- mean()
- average_only()
- avg_value()
- middle()
Answer: A) mean()
Explanation:
The mean() method calculates the arithmetic mean of values.
26. Which method returns the median value of a Series?
- middle()
- median()
- mid()
- center()
Answer: B) median()
Explanation:
The median() method calculates the median of values in a Series or DataFrame.
27. Which method calculates the sum of values?
- total()
- sum()
- add_all()
- aggregate_sum_only()
Answer: B) sum()
Explanation:
The sum() method computes the sum of values along a specified axis.
28. Which method returns the number of non-missing values?
- count()
- length()
- size_nonnull()
- nonmissing()
Answer: A) count()
Explanation:
The count() method counts non-missing values for Series and DataFrame objects.
29. Which method can calculate the standard deviation?
- std()
- standard()
- deviation()
- sd_only()
Answer: A) std()
Explanation:
The std() method computes the standard deviation of values.
30. Which method returns the minimum value in a Series or DataFrame?
- lowest()
- minimum()
- min()
- smallest_value()
Answer: C) min()
Explanation:
The min() method returns the minimum value along the specified axis.
31. Which method returns the maximum value?
- highest()
- max()
- maximum_value()
- largest_only()
Answer: B) max()
Explanation:
The max() method returns the maximum value along the specified axis.
32. Which accessor is commonly used for label-based selection in pandas?
- loc
- label_select
- bylabel
- labels_only
Answer: A) loc
Explanation:
The loc indexer is used primarily for label-based selection and can also accept boolean conditions.
33. Which accessor is commonly used for integer-position-based selection?
- iloc
- position
- indexpos
- atpos
Answer: A) iloc
Explanation:
The iloc indexer selects data based on integer positions.
34. Which expression selects a DataFrame column named Age?
- df(Age)
- df["Age"]
- df.column("Age")
- df.select("Age")
Answer: B) df["Age"]
Explanation:
Bracket notation such as df["Age"] is commonly used to select a DataFrame column.
35. Which operator is commonly used to filter pandas data based on a condition?
- ?
- []
- @@
- %%
Answer: B) []
Explanation:
Boolean conditions can be passed inside brackets, such as df[df["Age"] > 18], to filter rows.
36. Which function combines pandas objects along a particular axis?
- pd.concat()
- pd.combine_only()
- pd.append_data()
- pd.join_all()
Answer: A) pd.concat()
Explanation:
pd.concat() concatenates pandas objects along a particular axis.
37. Which pandas function performs database-style joins between DataFrames?
- pd.merge()
- pd.database_join()
- pd.sql_join()
- pd.connect()
Answer: A) pd.merge()
Explanation:
pd.merge() performs database-style joins between DataFrames or named Series.
38. Which merge type returns only matching keys from both DataFrames?
- outer
- left
- inner
- cross
Answer: C) inner
Explanation:
An inner merge keeps rows whose merge keys match between the two DataFrames.
39. Which merge type retains all keys from the left DataFrame?
- inner
- left
- right_only
- cross
Answer: B) left
Explanation:
A left merge keeps all rows from the left DataFrame and matches corresponding rows from the right DataFrame when available.
40. Which pandas function creates a spreadsheet-style pivot table?
- pd.pivot_table()
- pd.make_pivot()
- pd.spreadsheet()
- pd.table_pivot_only()
Answer: A) pd.pivot_table()
Explanation:
pd.pivot_table() creates a spreadsheet-style pivot table as a DataFrame.
41. Which pandas function can transform a DataFrame from wide format to long format?
- pd.melt()
- pd.longify()
- pd.wide_to_long_only()
- pd.reshape_long()
Answer: A) pd.melt()
Explanation:
pd.melt() unpivots a DataFrame from wide format to long format.
42. Which function can create a cross-tabulation of factors?
- pd.crosstab()
- pd.cross_table_only()
- pd.tabulate()
- pd.crossdata()
Answer: A) pd.crosstab()
Explanation:
pd.crosstab() computes a simple cross-tabulation of two or more factors.
43. Which function divides numerical values into discrete intervals?
- pd.cut()
- pd.divide_bins()
- pd.intervalize()
- pd.bucket()
Answer: A) pd.cut()
Explanation:
pd.cut() bins values into discrete intervals.
44. Which pandas function performs quantile-based discretization?
- pd.qcut()
- pd.quantile_bins()
- pd.quantize()
- pd.qbin()
Answer: A) pd.qcut()
Explanation:
pd.qcut() discretizes values based on sample quantiles.
45. Which method can remove duplicate rows from a DataFrame?
- drop_duplicates()
- remove_duplicates()
- unique_rows()
- delete_duplicate()
Answer: A) drop_duplicates()
Explanation:
The drop_duplicates() method removes duplicate rows according to the specified subset and related parameters.
46. Which method can replace specific values in a DataFrame?
- replace()
- change_value()
- modify_value()
- swap_data()
Answer: A) replace()
Explanation:
The replace() method can replace specified values in Series and DataFrame objects.
47. Which library is commonly used with pandas for numerical array operations?
- NumPy
- Flask
- BeautifulSoup
- Tkinter
Answer: A) NumPy
Explanation:
NumPy provides numerical arrays and mathematical operations and integrates closely with pandas for scientific and data-analysis workflows.
48. Which library is commonly used by pandas for plotting?
- Matplotlib
- Requests
- Flask
- PyTest
Answer: A) Matplotlib
Explanation:
Pandas plotting methods use Matplotlib for visualization. The resulting plot objects are Matplotlib objects.
49. Which pandas method can be used to create a plot from a DataFrame?
- plot()
- draw_chart()
- visualize()
- chart()
Answer: A) plot()
Explanation:
The plot() method provides a convenient interface for creating plots from Series and DataFrame objects.
50. Which statement best describes data analysis using pandas?
- It is limited to displaying tables
- It supports data loading, cleaning, selection, transformation, grouping, aggregation, merging, reshaping, and visualization
- It is used only for machine learning
- It can process only CSV files
Answer: B) It supports data loading, cleaning, selection, transformation, grouping, aggregation, merging, reshaping, and visualization
Explanation:
pandas provides a broad collection of data-analysis and manipulation features, including input/output, missing-data handling, selection, grouping, merging, reshaping, time-series operations, and plotting.
Advertisement
Advertisement