Unit 2 - Practice Quiz

CSE273 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which of the following is the primary data structure in Pandas used to represent a one-dimensional labeled array capable of holding data of any type?

A. DataFrame
B. Series
C. Panel
D. Array

2 Which Pandas data structure corresponds to a two-dimensional, size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns)?

A. Series
B. Matrix
C. DataFrame
D. Tensor

3 Which command is used to import the Pandas library using the standard alias?

A. import pandas as pd
B. import pandas as pds
C. import pandas
D. from pandas import *

4 What will be the index of the following Series if no index is explicitly provided?
s = pd.Series([10, 20, 30, 40])

A. 1, 2, 3, 4
B. 0, 1, 2, 3
C. 10, 20, 30, 40
D. A, B, C, D

5 Which function is used to read a CSV file into a Pandas DataFrame?

A. pd.read_file()
B. pd.import_csv()
C. pd.read_csv()
D. pd.load_csv()

6 When saving a DataFrame to a CSV file using to_csv(), which parameter is set to False to prevent writing the row numbers (index) into the file?

A. header
B. index
C. rows
D. save_index

7 Which method returns the first rows of a DataFrame?

A. df.tail(n)
B. df.top(n)
C. df.first(n)
D. df.head(n)

8 Which attribute of a DataFrame returns a tuple representing the dimensionality (rows, columns) of the DataFrame?

A. df.size
B. df.shape
C. df.ndim
D. df.length

9 Which method provides a concise summary of the DataFrame, including the data types of columns and the number of non-null values?

A. df.describe()
B. df.summary()
C. df.info()
D. df.types()

10 What is the purpose of df.describe()?

A. It gives technical information about memory usage.
B. It generates descriptive statistics (mean, std, min, max, etc.) of numeric columns.
C. It describes the column names only.
D. It visualizes the data distribution.

11 How do you select a single column named 'Age' from a DataFrame df to return it as a Series?

A. df['Age']
B. df.select('Age')
C. df(Age)
D. df.loc['Age']

12 What is the key difference between .loc[] and .iloc[]?

A. .loc[] works on integer positions; .iloc[] works on labels.
B. .loc[] works on labels; .iloc[] works on integer positions.
C. Both function identically.
D. .loc[] is for rows; .iloc[] is for columns.

13 Consider a DataFrame df. Which command selects the first 5 rows and the first 3 columns using integer slicing?

A. df.loc[0:5, 0:3]
B. df.iloc[0:5, 0:3]
C. df.iloc[1:5, 1:3]
D. df.loc[:5, :3]

14 Which logical operator allows filtering a DataFrame based on multiple conditions (AND logic)?

A. and
B. &
C. &&
D. +

15 How would you filter a DataFrame df to show rows where the column 'Salary' is greater than 50000?

A. df.where(Salary > 50000)
B. df['Salary' > 50000]
C. df[df['Salary'] > 50000]
D. df.filter('Salary' > 50000)

16 Which function is used to check for missing or null values in a DataFrame?

A. df.missing()
B. df.check_null()
C. df.isnull()
D. df.void()

17 To drop a column named 'temp' from a DataFrame df, which command is used?

A. df.drop('temp', axis=0)
B. df.drop('temp', axis=1)
C. df.remove('temp')
D. df.delete('temp')

18 Which function is used to view the unique values in a specific Series/column?

A. unique()
B. distinct()
C. values()
D. singular()

19 What does df.columns return?

A. The data types of the columns.
B. The content of the first column.
C. An index object containing the column labels.
D. The number of columns.

20 Which Matplotlib module is most commonly imported for plotting?

A. matplotlib.plot
B. matplotlib.pyplot
C. matplotlib.graph
D. matplotlib.figure

21 In Matplotlib, which function is used to display the plot to the user?

A. plt.display()
B. plt.render()
C. plt.show()
D. plt.view()

22 Which plot type is best suited for visualizing the trend of a variable over time?

A. Scatter plot
B. Histogram
C. Line plot
D. Pie chart

23 What is the command to create a simple line plot of versus using Pyplot?

A. plt.line(x, y)
B. plt.plot(x, y)
C. plt.draw(x, y)
D. plt.scatter(x, y)

24 Which type of plot is used to represent the frequency distribution of a continuous variable?

A. Bar plot
B. Histogram
C. Scatter plot
D. Line plot

25 In a histogram, what does the parameter bins control?

A. The color of the bars.
B. The number of intervals the data is divided into.
C. The thickness of the lines.
D. The transparency of the plot.

26 Which function creates a bar plot?

A. plt.histogram()
B. plt.bar()
C. plt.box()
D. plt.columns()

27 A scatter plot is primarily used to visualize:

A. The distribution of a single variable.
B. The relationship or correlation between two numerical variables.
C. Parts of a whole.
D. Hierarchical data.

28 Which parameter in plt.scatter() controls the size of the markers?

A. s
B. size
C. m
D. width

29 Which plot is most effective for showing the proportional contribution of categories to a whole?

A. Scatter plot
B. Line plot
C. Pie chart
D. Histogram

30 In plt.pie(), which parameter is used to offset a slice from the center (often to highlight it)?

A. pop
B. explode
C. offset
D. detach

31 How do you add a title to a Matplotlib plot?

A. plt.header('Title')
B. plt.title('Title')
C. plt.caption('Title')
D. plt.name('Title')

32 Which functions are used to label the x-axis and y-axis respectively?

A. plt.x_label() and plt.y_label()
B. plt.label_x() and plt.label_y()
C. plt.xlabel() and plt.ylabel()
D. plt.axis_x() and plt.axis_y()

33 To add a legend to a plot identifying the various data series, which function is called?

A. plt.key()
B. plt.legend()
C. plt.map()
D. plt.labels()

34 In Matplotlib, what does the argument alpha control?

A. Line width
B. Marker size
C. Transparency/Opacity
D. Color intensity

35 Which string format string would produce a red dashed line in plt.plot()?

A. 'r--'
B. 'red-dash'
C. 'r-'
D. 'r.'

36 What is the purpose of plt.figure(figsize=(10, 5))?

A. It limits the axis range to 10 and 5.
B. It creates a new figure window with a width of 10 inches and height of 5 inches.
C. It sets the resolution to 10x5 pixels.
D. It creates a subplot grid of 10 rows and 5 columns.

37 Which function is used to create multiple plots in a single figure (grid layout)?

A. plt.multiplot()
B. plt.subplot()
C. plt.gridplot()
D. plt.facets()

38 If you use plt.subplot(2, 2, 3), which position in the grid is selected?

A. Top-left
B. Top-right
C. Bottom-left
D. Bottom-right

39 Which command saves the current plot as an image file named 'plot.png'?

A. plt.save('plot.png')
B. plt.savefig('plot.png')
C. plt.export('plot.png')
D. plt.download('plot.png')

40 Which Pandas method allows sorting a DataFrame by values in a specific column?

A. df.sort()
B. df.sort_values()
C. df.order_by()
D. df.rank()

41 In a Bar plot, how do you rotate x-axis labels if they are overlapping?

A. plt.xticks(rotation=90)
B. plt.rotate_x(90)
C. plt.xlabel(rotation=90)
D. plt.axis(rotation=90)

42 How do you enable grid lines on a Matplotlib plot?

A. plt.grid(True)
B. plt.show_grid()
C. plt.lines(True)
D. plt.style.use('grid')

43 If you want to set the range of the x-axis manually from 0 to 100, which function do you use?

A. plt.range_x(0, 100)
B. plt.xlim(0, 100)
C. plt.x_limit(0, 100)
D. plt.axis(x=100)

44 What is the correct syntax to create a DataFrame from a dictionary of lists?

A. pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
B. pd.Series({'A': [1, 2], 'B': [3, 4]})
C. pd.Table({'A': [1, 2], 'B': [3, 4]})
D. pd.DataFrame([{'A': 1, 'B': 3}, {'A': 2, 'B': 4}])

45 When reading a CSV with read_csv, which parameter specifies that the file contains no header row?

A. header=None
B. header=False
C. no_header=True
D. skip_header=True

46 Which method allows you to rename columns in a DataFrame?

A. df.change_name()
B. df.replace()
C. df.rename()
D. df.columns.name()

47 What happens if you apply a mathematical operation (like + 5) to a Pandas Series?

A. It raises an error.
B. It adds 5 to the index only.
C. It adds 5 to every element in the Series (vectorization).
D. It appends 5 to the end of the Series.

48 To change the color of bars in a bar plot to green, which argument is passed to plt.bar()?

A. c='green'
B. color='green'
C. fill='green'
D. shade='green'

49 How can you access the values of a Series as a numpy array?

A. series.to_array()
B. series.values
C. series.numpy()
D. series.data

50 Which function is best used to visualize the distribution of data and detect outliers?

A. plt.pie()
B. plt.scatter()
C. plt.boxplot()
D. plt.line()