Exit Chapter 01 Β· πŸ“˜ Data Handling Using Pandas – I β€” Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 50 0 correct so far

πŸ“˜ Data Handling Using Pandas – I Quiz

Q1.

Which library is primarily used for data manipulation and analysis in Python?

Explanation

Pandas is the core library designed for structured data manipulation and analysis.

Q2.

What is the standard convention for importing the Pandas library?

Explanation

The universal alias for importing Pandas is pd.

Q3.

Which Pandas data structure represents a one-dimensional labeled array?

Explanation

A Series is a 1-D labeled array capable of holding data of any type.

Q4.

Which Pandas data structure represents a two-dimensional labeled data structure with columns of potentially different types?

Explanation

A DataFrame is a 2-D data structure, similar to a table or spreadsheet.

Q5.

What is the key difference between a Pandas Series and a standard Python list?

Explanation

Unlike lists which use integer positions, Series supports custom index labels.

Q6.

If you create a Series from a Python dictionary, what becomes the index?

Explanation

When creating a Series from a dict, the dictionary keys automatically become the index labels.

Q7.

Which attribute returns the underlying data of a Series as a NumPy array?

Explanation

s.values returns the data as a NumPy ndarray.

Q8.

What does the shape attribute of a DataFrame return?

Explanation

df.shape returns a tuple representing the dimensionality: (rows, columns).

Q9.

Which method is used to view the first 5 rows of a DataFrame by default?

Explanation

df.head() returns the first n rows (default is 5).

Q10.

How do you access a column named 'Marks' in a DataFrame df?

Explanation

Columns are accessed using bracket notation with the column name as a string: df['Marks'].

Q11.

What is the main difference between loc and iloc?

Explanation

loc selects data by label/name, whereas iloc selects by integer index/position.

Q12.

When slicing using loc['A':'C'], is the end bound 'C' included?

Explanation

Slicing with labels using loc is inclusive of both the start and stop bounds.

Q13.

When slicing using iloc[0:3], which rows are selected?

Explanation

Slicing with iloc (integers) follows Python standard slicing: start is inclusive, end is exclusive. So, 0, 1, 2.

Q14.

Which command is used to remove a column 'Grade' from DataFrame df?

Explanation

drop is used to remove data. axis=1 specifies that we are dropping a column.

Q15.

What function generates descriptive statistics (mean, std, min, max) for numeric columns?

Explanation

describe() computes summary statistics of the Series or DataFrame.

Q16.

How would you filter a DataFrame df to show rows where 'Marks' > 80?

Explanation

Boolean indexing requires passing the condition df['Marks'] > 80 inside the brackets.

Q17.

Which method sorts the DataFrame by the values of a specific column?

Explanation

sort_values() sorts a DataFrame by its values (columns).

Q18.

If you add two Series, how does Pandas handle indices that do not match?

Explanation

Pandas aligns data by index. Indices present in one but not the other result in NaN.

Q19.

What is the result of df.size?

Explanation

size returns the total number of elements in the object.

Q20.

Which attribute gives the index (row labels) of the DataFrame?

Explanation

df.index contains the labels for the rows.

Q21.

To transpose a DataFrame (swap rows and columns), which attribute is used?

Explanation

df.T is the accessor for the transpose of the DataFrame.

Q22.

How do you check for missing values in a DataFrame?

Explanation

isnull() (or isna()) returns a boolean mask indicating missing values.

Q23.

Which code correctly creates a DataFrame from a dictionary of lists?

Explanation

The correct syntax passes a dictionary where keys are column names and values are lists of data.

Q24.

What happens if you use pd.Series(5, index=['a', 'b', 'c'])?

Explanation

This is called Scalar broadcasting. The value 5 is repeated for each label in the index.

Q25.

Which argument in df.drop() specifies that we want to drop a row?

Explanation

axis=0 refers to the index (rows), while axis=1 refers to columns.

Q26.

What allows Pandas to perform operations on entire arrays without loops?

Explanation

Vectorization allows applying operations to whole arrays/columns at once efficiently.

Q27.

Which method provides a concise summary of a DataFrame including data types and non-null counts?

Explanation

df.info() prints information about the DataFrame including the index dtype, columns, non-null values and memory usage.

Q28.

How can you rename columns in a DataFrame?

Explanation

rename method with the columns parameter taking a dictionary is the standard way to rename specific columns.

Q29.

If s is a Series, what does s.ndim return?

Explanation

A Series is strictly 1-dimensional, so ndim is always 1.

Q30.

If df is a DataFrame, what does df.ndim return?

Explanation

A DataFrame is strictly 2-dimensional, so ndim is always 2.

Q31.

To select multiple columns 'A' and 'B', which syntax is correct?

Explanation

You must pass a list of column names inside the brackets, resulting in double brackets: df[['A', 'B']].

Q32.

What is the default index type if none is provided when creating a DataFrame?

Explanation

Pandas assigns a default RangeIndex starting from 0.

Q33.

Which property indicates whether a Series is empty?

Explanation

s.empty returns a boolean True if the Series/DataFrame contains no elements.

Q34.

Which function allows applying a custom function to every element of a Series?

Explanation

apply() invokes a function on values of the Series.

Q35.

What does df.loc['A', 'B'] access?

Explanation

loc[row_label, column_label] accesses a specific scalar value.

Q36.

How do you verify the data types of all columns in a DataFrame?

Explanation

df.dtypes returns the data type of each column in the DataFrame.

Q37.

Which method allows you to fill missing values with a specific number?

Explanation

fillna(value) is used to fill NA/NaN values using the specified method or value.

Q38.

What implies that a pandas object is 'mutable'?

Explanation

Value mutability means you can modify the data contained in the structure.

Q39.

Which operator is used for element-wise logical AND in Pandas filtering?

Explanation

In Pandas/NumPy boolean indexing, & is used for element-wise AND (unlike Python's and).

Q40.

Which operator is used for element-wise logical OR in Pandas filtering?

Explanation

| is the bitwise OR operator used for element-wise logical OR in Pandas.

Q41.

What error do you get if you try to access a column that does not exist?

Explanation

A KeyError is raised when a dictionary key (or column name) is not found.

Q42.

Which method returns the last n rows of a DataFrame?

Explanation

tail(n) returns the last n rows.

Q43.

Can a DataFrame column contain mixed data types (e.g., integers and strings)?

Explanation

Yes, Pandas falls back to the 'object' dtype (generic Python objects) if types are mixed.

Q44.

What is the output of len(df)?

Explanation

len() on a DataFrame returns the number of rows (length of the index).

Q45.

To sort the index labels of a Series s, which method is used?

Explanation

sort_index() sorts the object by its index labels.

Q46.

If you create pd.Series([10, 20]), what are the default index labels?

Explanation

The default RangeIndex starts at 0. So indices are 0 and 1.

Q47.

How do you add a new row to a DataFrame using loc?

Explanation

Assigning data to a non-existent label using loc creates a new row: df.loc['new'] = ...

Q48.

What does df.columns return?

Explanation

columns attribute returns an Index object containing the column labels.

Q49.

Which of the following is NOT a valid way to create a DataFrame?

Explanation

A single integer cannot be converted into a 2D DataFrame structure directly without context.

Q50.

If s = pd.Series([1, 2, 3], index=['a', 'b', 'c']), what is s['b']?

Explanation

s['b'] accesses the value associated with label 'b', which is 2.