wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Pandas and Data Manipulation Quiz 3 часть

Total questions: 29

Worksheet time: 15mins

Name
Class
Date
1.

Output of this code? import pandas as pd df = pd.read_csv('data.csv', skip_blank_lines=True)

a)

Ignores blank lines in the CSV

b)

Reads blank lines as NaN

c)

Error

d)

Deletes CSV

2.

What is the output of this code? import pandas as pd df = pd.read_csv('data.csv', low_memory=False)

a)

Prevents dtype guessing and ensures proper memory usage

b)

Reads CSV in chunks

c)

Converts everything to string

d)

Error

3.

What does this code do? import pandas as pd df = pd.read_sql('SELECT * FROM table1', conn, index_col='ID')

a)

Reads SQL table and sets ‘ID’ as index

b)

Writes SQL table

c)

Converts SQL table to CSV

d)

Creates a new SQL table

4.

What does this code do? import pandas as pd df = pd.read_csv('data.csv', header=None)

a)

Reads CSV without using the first row as header

b)

Reads CSV using the first row as header

c)

Reads only the first row

d)

Writes CSV without header

5.

How do you remove rows with all NaN values? df.dropna(how='all', inplace=True)

a)

Drops rows where all values are NaN

b)

Drops any row with NaN

c)

Drops column with NaN

d)

Fills NaN

6.

How can you strip special characters from a string column? df['col'] = df['col'].str.replace('[^a-zA-Z0-9]', '', regex=True)

a)

Removes all non-alphanumeric characters

b)

Converts to lowercase

c)

Converts to uppercase

d)

Replaces spaces with underscores

7.

Output of IQR outlier filtering code?

a)

Filters out outliers based on IQR

b)

Keeps only outliers

c)

Drops all rows

d)

Error

8.

How do you replace all infinite values with NaN? import numpy as np df.replace([np.inf, -np.inf], np.nan, inplace=True)

a)

Replaces +inf/-inf with NaN

b)

Drops infinite values

c)

Converts to zero

d)

Raises error

9.

What does this code do? df['col'] = df['col'].str.lower()

a)

Converts all strings in the column to lowercase

b)

Converts to uppercase

c)

Strips spaces

d)

Deletes column

10.

How can you remove columns with more than 50% missing values? df.dropna(thresh=len(df)*0.5, axis=1, inplace=True)

a)

Drops columns with more than 50% NaN

b)

Drops rows with >50% NaN

c)

Replaces NaN with 0

d)

Keeps only rows with >50% non-NaN

11.

What does this code produce? pd.concat([df1, df2], axis=0, ignore_index=True)

a)

Stacks df1 and df2 vertically and resets the index

b)

Stacks horizontally

c)

Performs a merge

d)

Produces an error

12.

What is the result of this code? pd.melt(df, id_vars=['X'])

a)

Keeps ‘X’ fixed and unpivots ‘Y’ into long format

b)

Keeps ‘Y’ fixed and unpivots ‘X’

c)

Drops column ‘Y’

d)

Produces an error

13.

What does this code do? pd.merge(df1, df2, how='outer', on='key')

a)

Outer join: keeps all keys from both, fills missing with NaN

b)

Left join

c)

Inner join

d)

Right join

14.

Output of pivot code (long to wide)?

a)

Reshapes from long to wide format with ‘id’ as index

b)

Reshapes from wide to long

c)

Drops column ‘value’

d)

Produces an error

15.

What is the difference between merge and concat?

a)

merge joins based on columns/keys, concat stacks along axis

b)

merge concatenates, concat joins

c)

Both do the same thing

d)

merge deletes duplicates, concat does not

16.

How can you reorder levels in a MultiIndex? df.reorder_levels([1,0])

a)

Switches the positions of the levels

b)

Sorts the index

c)

Drops a level

d)

Creates a new column

17.

What is the key difference between reorder_levels() and swaplevel()?

a)

reorder_levels() allows arbitrary reordering, swaplevel() only swaps two levels

b)

swaplevel() can reorder multiple, reorder_levels() swaps

c)

reorder_levels() on non-hierarchical, swaplevel() cannot

d)

swaplevel() requires all levels

18.

In a merge(), what does how=‘outer’ do?

a)

Performs a union of keys from both DataFrames

b)

Only common keys

c)

Left only

d)

Right only

19.

Output of df.loc[‘A’] in MultiIndex?

a)

Selects all rows where first level is ‘A’

b)

Second level ‘A’

c)

Columns named ‘A’

d)

Error

20.

How do you rotate y-axis tick labels? plt.yticks(rotation=90)

a)

Rotates y-axis labels by 90 degrees

b)

Rotates x-axis

c)

Rotates plot

d)

Error

21.

How do you change bar width in a bar plot? df['A'].value_counts().plot.bar(width=0.3)

a)

Sets bar width to 0.3

b)

Sets spacing

c)

Changes color

d)

Produces an error

22.

How do you plot a histogram with normalized frequencies? df['A'].plot.hist(density=True)

a)

Plots histogram normalized to form a probability density

b)

Plots raw counts

c)

Plots line plot

d)

Produces an error

23.

Which parameters control the spacing between subplots in matplotlib?

a)

wspace and hspace

b)

width_space and height_space

c)

subplot_space and grid_space

d)

padding_x and padding_y

24.

What is the default behavior for connecting points in a matplotlib line plot?

a)

Linear interpolation

b)

Cubic interpolation

c)

Step-wise connection

d)

No connection

25.

Which function is used to set the x-axis label in matplotlib?

a)

set_xlabel()

b)

set_xlim()

c)

set_xticks()

d)

set_title()

26.

Which function is used to create a legend in a plot?

a)

plt.legend()

b)

plt.show_legend()

c)

plt.add_legend()

d)

plt.legend_box()

27.

How can you customize the row and column variables in a seaborn FacetGrid?

a)

Pass them to the row and col parameters of sns.FacetGrid()

b)

Set them using grid.set_rows() and grid.set_cols()

c)

Define them in the facet_vars parameter

d)

Use the rows and columns parameters

28.

What happens to missing values in a group key during a GroupBy operation?

a)

They are excluded from the result

b)

They are replaced with zeros

c)

They are included as a separate group

d)

An error is raised

29.

When grouping by multiple keys, what is the type of the first element in the group tuple?

a)

A tuple of key values

b)

A single key value

c)

A pandas DataFrame

d)

A list of grouped rows