Unit 2 - Practice Quiz
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?
2 Which Pandas data structure corresponds to a two-dimensional, size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns)?
3 Which command is used to import the Pandas library using the standard alias?
import pandas as pd
import pandas as pds
import pandas
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])
5 Which function is used to read a CSV file into a Pandas DataFrame?
pd.read_file()
pd.import_csv()
pd.read_csv()
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?
header
index
rows
save_index
7 Which method returns the first rows of a DataFrame?
df.tail(n)
df.top(n)
df.first(n)
df.head(n)
8 Which attribute of a DataFrame returns a tuple representing the dimensionality (rows, columns) of the DataFrame?
df.size
df.shape
df.ndim
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?
df.describe()
df.summary()
df.info()
df.types()
10
What is the purpose of df.describe()?
11
How do you select a single column named 'Age' from a DataFrame df to return it as a Series?
df['Age']
df.select('Age')
df(Age)
df.loc['Age']
12
What is the key difference between .loc[] and .iloc[]?
.loc[] works on integer positions; .iloc[] works on labels.
.loc[] works on labels; .iloc[] works on integer positions.
.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?
df.loc[0:5, 0:3]
df.iloc[0:5, 0:3]
df.iloc[1:5, 1:3]
df.loc[:5, :3]
14 Which logical operator allows filtering a DataFrame based on multiple conditions (AND logic)?
and
&
&&
+
15
How would you filter a DataFrame df to show rows where the column 'Salary' is greater than 50000?
df.where(Salary > 50000)
df['Salary' > 50000]
df[df['Salary'] > 50000]
df.filter('Salary' > 50000)
16 Which function is used to check for missing or null values in a DataFrame?
df.missing()
df.check_null()
df.isnull()
df.void()
17
To drop a column named 'temp' from a DataFrame df, which command is used?
df.drop('temp', axis=0)
df.drop('temp', axis=1)
df.remove('temp')
df.delete('temp')
18 Which function is used to view the unique values in a specific Series/column?
unique()
distinct()
values()
singular()
19
What does df.columns return?
20 Which Matplotlib module is most commonly imported for plotting?
matplotlib.plot
matplotlib.pyplot
matplotlib.graph
matplotlib.figure
21 In Matplotlib, which function is used to display the plot to the user?
plt.display()
plt.render()
plt.show()
plt.view()
22 Which plot type is best suited for visualizing the trend of a variable over time?
23 What is the command to create a simple line plot of versus using Pyplot?
plt.line(x, y)
plt.plot(x, y)
plt.draw(x, y)
plt.scatter(x, y)
24 Which type of plot is used to represent the frequency distribution of a continuous variable?
25
In a histogram, what does the parameter bins control?
26 Which function creates a bar plot?
plt.histogram()
plt.bar()
plt.box()
plt.columns()
27 A scatter plot is primarily used to visualize:
28
Which parameter in plt.scatter() controls the size of the markers?
s
size
m
width
29 Which plot is most effective for showing the proportional contribution of categories to a whole?
30
In plt.pie(), which parameter is used to offset a slice from the center (often to highlight it)?
pop
explode
offset
detach
31 How do you add a title to a Matplotlib plot?
plt.header('Title')
plt.title('Title')
plt.caption('Title')
plt.name('Title')
32 Which functions are used to label the x-axis and y-axis respectively?
plt.x_label() and plt.y_label()
plt.label_x() and plt.label_y()
plt.xlabel() and plt.ylabel()
plt.axis_x() and plt.axis_y()
33 To add a legend to a plot identifying the various data series, which function is called?
plt.key()
plt.legend()
plt.map()
plt.labels()
34
In Matplotlib, what does the argument alpha control?
35
Which string format string would produce a red dashed line in plt.plot()?
'r--'
'red-dash'
'r-'
'r.'
36
What is the purpose of plt.figure(figsize=(10, 5))?
37 Which function is used to create multiple plots in a single figure (grid layout)?
plt.multiplot()
plt.subplot()
plt.gridplot()
plt.facets()
38
If you use plt.subplot(2, 2, 3), which position in the grid is selected?
39 Which command saves the current plot as an image file named 'plot.png'?
plt.save('plot.png')
plt.savefig('plot.png')
plt.export('plot.png')
plt.download('plot.png')
40 Which Pandas method allows sorting a DataFrame by values in a specific column?
df.sort()
df.sort_values()
df.order_by()
df.rank()
41 In a Bar plot, how do you rotate x-axis labels if they are overlapping?
plt.xticks(rotation=90)
plt.rotate_x(90)
plt.xlabel(rotation=90)
plt.axis(rotation=90)
42 How do you enable grid lines on a Matplotlib plot?
plt.grid(True)
plt.show_grid()
plt.lines(True)
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?
plt.range_x(0, 100)
plt.xlim(0, 100)
plt.x_limit(0, 100)
plt.axis(x=100)
44 What is the correct syntax to create a DataFrame from a dictionary of lists?
pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
pd.Series({'A': [1, 2], 'B': [3, 4]})
pd.Table({'A': [1, 2], 'B': [3, 4]})
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?
header=None
header=False
no_header=True
skip_header=True
46 Which method allows you to rename columns in a DataFrame?
df.change_name()
df.replace()
df.rename()
df.columns.name()
47
What happens if you apply a mathematical operation (like + 5) to a Pandas Series?
48
To change the color of bars in a bar plot to green, which argument is passed to plt.bar()?
c='green'
color='green'
fill='green'
shade='green'
49 How can you access the values of a Series as a numpy array?
series.to_array()
series.values
series.numpy()
series.data
50 Which function is best used to visualize the distribution of data and detect outliers?
plt.pie()
plt.scatter()
plt.boxplot()
plt.line()