RBSE SS Informatics Practices study materials
RBSE SS Informatics Practices study resources

RBSE SS Informatics Practices practice questions

One question at a time. Build your RBSE SS Informatics Practices understanding.

First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A Series is created with the statement pd.Series({'a': 10, 'b': 20, 'c': 30}). What does the resulting index contain?

  1. 10, 20, 30
  2. 'a', 'b', 'c' Correct answer.
  3. 0, 1, 2
  4. A single label 'index'

Explanation

When a Series is built from a dictionary, pandas takes the dictionary keys as the index labels and the dictionary values as the data, preserving the order in which the keys were written. A default RangeIndex of 0, 1, 2 appears only when no index is supplied, as happens when the data is a plain list.

Question 2Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Consider s1 = pd.Series([1, 2], index=['a', 'b']), s2 = pd.Series([3, 4], index=['b', 'c']) and df = pd.DataFrame({'P': s1, 'Q': s2}). What does df contain?

  1. Three rows, with NaN for missing values Correct answer.
  2. Three rows, with 0 filled in for missing values
  3. Two rows, since incomplete rows are dropped
  4. A ValueError, since the two indexes differ

Explanation

Building a DataFrame from a dictionary of Series aligns the Series by their index labels rather than by position. The row index becomes the union of all labels, so rows 'a', 'b' and 'c' appear, and any label absent from a particular Series gets the missing-value marker NaN instead of zero or an error.

Question 3Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

With s = pd.Series([10, 20, 30, 40], index=['w', 'x', 'y', 'z']), what labels does the result of s['x':'z'] cover?

  1. Only 'x'
  2. 'x', 'y' and 'z' Correct answer.
  3. 'x' and 'y'
  4. All four labels of the Series

Explanation

Slicing a Series with square brackets and label values follows label semantics, where the stop label is included in the result. Therefore s['x':'z'] returns the three elements stored at 'x', 'y' and 'z'. Positional slices such as s[1:3] behave differently, because there the stop position is excluded.

Question 4Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Which expression returns the third row of a DataFrame named df as a Series, regardless of the labels carried by its index?

  1. df.loc[2]
  2. df.iloc[2] Correct answer.
  3. df[2:3]
  4. df[2]

Explanation

The iloc indexer is purely positional and zero-based, so integer 2 always addresses the third row from the top. loc works on index labels, a bare df[2] is interpreted as a column request, and df[2:3] returns a DataFrame slice rather than a single Series.

Question 5Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

In the loop for i, row in df.iterrows():, what does the variable row hold on each pass?

  1. A tuple holding the row's values in column order
  2. A DataFrame containing only the current row
  3. A Series for one column, indexed by the row labels
  4. A Series for one row, indexed by column labels Correct answer.

Explanation

iterrows() walks down the rows and yields a pair each time: the row's index label and a Series holding that row's data. The Series is indexed by the column names, so row['Marks'] fetches a value from the current row.

Question 6Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A DataFrame df has 4 rows, and the statement df['Result'] = 'Pass' is executed. What is stored in the new column?

  1. The value 'Pass' is stored once, as the column's name
  2. All 4 rows get 'Pass', because a single value is broadcast Correct answer.
  3. A ValueError, because a scalar cannot be assigned to a column
  4. Only the first row gets 'Pass'; the rest stay NaN

Explanation

Assigning a single scalar value to a new column label broadcasts that value across every existing row, so all four entries become 'Pass'. Only when the right-hand side is a sequence or Series must its length match the rows or its labels align with the index.

Question 7Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

For s = pd.Series([10, 20, 30], index=[3, 4, 5]), what does the expression s[3] evaluate to?

  1. 10 Correct answer.
  2. A KeyError, because 3 is not a position in the Series
  3. 30
  4. 20

Explanation

When a Series carries an integer index, a single integer inside square brackets is matched against those index labels first. Label 3 holds the first value, so s[3] returns 10. Unambiguous positional access would be written s.iloc[0], and label access is clearer as s.loc[3].

Question 8Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A DataFrame df contains 6 rows, and df.head(-2) is executed. Which rows does it return?

  1. The first 4 rows Correct answer.
  2. An error, because head() accepts only positive counts
  3. Just the first 2 rows
  4. Just the last 2 rows

Explanation

A negative argument to head() is counted from the end of the DataFrame, so head(-2) drops the last two rows and keeps the four rows before them. The companion method tail(-2) works the same way in the opposite direction, dropping the first two rows.

Question 9Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

For s = pd.Series([5, 6, 7], index=['a', 'b', 'c']), what does s.reindex(['b', 'c', 'd']) produce?

  1. Values 6 and 7 only, because unknown labels are dropped
  2. A KeyError, because 'd' is not in the original index
  3. Values 6 and 7 for 'b' and 'c', and NaN for 'd' Correct answer.
  4. Values 5, 6 and 7 for 'b', 'c' and 'd'

Explanation

reindex() conforms the object to a new list of labels: labels already present keep their existing values, labels that are new are created and filled with NaN, and labels missing from the requested list are removed. It therefore changes the shape of the Series rather than raising an error on unseen labels.

Question 10Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A DataFrame df holds 5 rows and 3 columns. What does df.shape return?

  1. The list ['Rows', 'Columns']
  2. The tuple (3, 5)
  3. The tuple (5, 3) Correct answer.
  4. The integer 15

Explanation

shape is a tuple that reports the dimensions as (number of rows, number of columns), so it is (5, 3) here. The individual counts are available as df.shape[0] for rows and df.shape[1] for columns, which are used constantly when writing loops over a DataFrame.

Question 11Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

What values are stored in the Series produced by pd.Series(5, index=['p', 'q', 'r'])?

  1. Only one value, 5, at index 'p'
  2. 5 in every position, giving [5, 5, 5] Correct answer.
  3. NaN in every position because no data list was supplied
  4. It raises a ValueError because a list is required

Explanation

When the first argument to pd.Series is a scalar, pandas broadcasts that scalar to every label in the index. With three labels and the value 5, the Series holds three copies of 5 and uses 'p', 'q', 'r' as its index.

Question 12Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Which attribute of a DataFrame named df holds the row labels?

  1. df.shape
  2. df.columns
  3. df.values
  4. df.index Correct answer.

Explanation

The index attribute stores the row labels of a DataFrame, while columns stores the column labels. The shape attribute reports dimensions, and values returns the underlying data without labels.

Question 13Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

When a for loop is written as for item in s: over a pandas Series s, what does item receive on each pass?

  1. The value of the current element Correct answer.
  2. The index label of the current element
  3. A tuple containing the index label and value
  4. The name of the Series

Explanation

Iterating directly over a Series yields its values in order, not its index labels. To get label-value pairs, the items() method must be used explicitly.

Question 14Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Consider df = pd.DataFrame({'A': pd.Series([1, 2], index=['x', 'y']), 'B': pd.Series([3, 4], index=['y', 'z'])}). What is the value of df.loc['z', 'A']?

  1. 1
  2. 0
  3. NaN Correct answer.
  4. 2

Explanation

When a DataFrame is built from Series with different indexes, pandas aligns them on the union of labels. Row 'z' exists because of column B, but column A has no value for 'z', so pandas fills that cell with NaN.

Question 15Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

For a DataFrame df, what does the expression df.iloc[:, 1] return?

  1. A DataFrame containing all columns
  2. The second column as a Series Correct answer.
  3. The first column as a Series
  4. The second row as a Series

Explanation

In iloc, the first position selects rows and the second selects columns. The colon keeps every row, and column position 1 selects the second column, returning it as a Series.

Question 16Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Which expression returns only those rows of df for which the value in column 'Marks' is greater than 50?

  1. df['Marks'] > 50
  2. df.loc['Marks'] > 50
  3. df[df['Marks'] > 50] Correct answer.
  4. df.iloc['Marks'] > 50

Explanation

The comparison df['Marks'] > 50 creates a Boolean Series, and placing it inside df[...] filters the rows where the condition is True. The comparison alone only produces True and False values.

Question 17Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Let s1 = pd.Series([10, 20], index=['a', 'b']) and s2 = pd.Series([5, 6], index=['b', 'c']). What is the value at label 'a' in s1 + s2?

  1. 0
  2. 10
  3. NaN Correct answer.
  4. 15

Explanation

Series arithmetic aligns operands by index label before adding. Label 'a' appears only in s1, so there is no matching value in s2 and the result at 'a' is NaN.

Question 18Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A DataFrame df has row labels ['x', 'y'] and column labels ['A', 'B']. What does df.loc['y', 'B'] return?

  1. A one-row DataFrame
  2. The entire row labelled 'y' as a Series
  3. The entire column labelled 'B' as a Series
  4. A single scalar value from row 'y' and column 'B' Correct answer.

Explanation

When loc receives both a row label and a column label separated by a comma, it selects one cell. The result is the scalar stored at that intersection, not a full row or column.

Question 19Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Let s = pd.Series([10, 20, 30], index=['a', 'a', 'b']). What does s['a'] return?

  1. The single integer 20
  2. The single integer 10
  3. A KeyError because index labels must be unique
  4. A Series containing 10 and 20 Correct answer.

Explanation

A pandas Series can carry duplicate index labels. When a duplicated label is used for selection, pandas returns all matching entries as a Series rather than reducing them to one scalar.

Question 20Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Given df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) and df2 = pd.DataFrame({'B': [10, 20], 'C': [30, 40]}), what is df1.add(df2, fill_value=0).loc[0, 'C']?

  1. 0
  2. 40
  3. NaN
  4. 30 Correct answer.

Explanation

The add method aligns the two DataFrames by row and column labels and uses fill_value=0 where one frame lacks an entry. Column C exists only in df2, so row 0 receives 0 + 30, which equals 30.

Question 21Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A DataFrame is created with the statement df = pd.DataFrame({'Name': ['Amit', 'Bina'], 'Marks': [78, 85]}). What do the strings 'Name' and 'Marks' become in the resulting DataFrame?

  1. The index of the Series inside each column
  2. Row labels of df
  3. The first row of values in df
  4. Column labels of df Correct answer.

Explanation

In a dictionary used to build a DataFrame, each key supplies a column label and each list supplies the values for that column. The row labels are not taken from these keys; pandas assigns the default integer index 0 and 1. Therefore 'Name' and 'Marks' appear in df.columns.

Question 22Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

After the statement s = pd.Series([4, 8, 12]) is executed, what does s.index contain?

  1. The values 4, 8 and 12
  2. An empty index
  3. The labels 0, 1 and 2 Correct answer.
  4. The labels 1, 2 and 3

Explanation

When no index is supplied, pandas creates a default RangeIndex that starts at 0 and increases by 1 for each element. For three values this gives the labels 0, 1 and 2. The data values 4, 8 and 12 are stored separately from these labels.

Question 23Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

For a DataFrame df that has a column named 'Marks', what does the expression df['Marks'] return?

  1. A scalar equal to the first Marks value
  2. A Series of Marks values indexed by row labels Correct answer.
  3. A DataFrame object containing only the Marks column
  4. A Python list of all Marks values

Explanation

Selecting a single column with df['Marks'] returns a pandas Series. That Series uses the DataFrame's row labels as its own index and contains the Marks column's values. A DataFrame would be returned only if a list of column names were passed, such as df[['Marks']].

Question 24Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A DataFrame df has columns 'Math' and 'Sci'. After df['Total'] = df['Math'] + df['Sci'] is executed, what is stored in the new column 'Total'?

  1. Only the sum of the first values of Math and Sci
  2. The row-wise sum of Math and Sci for each row Correct answer.
  3. A single total obtained by adding every entry of both columns
  4. The text 'Math + Sci' repeated in every row

Explanation

Assigning to df['Total'] creates a new column because 'Total' is not already a column label. The right-hand expression adds the two Series column by column, using matching row labels, so each row receives its own Math plus Sci value. The operation is vectorised and does not reduce the columns to a single total.

Question 25Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Which expression selects the rows of df where the column 'Age' is at least 18 and the column 'City' is exactly 'Jaipur'?

  1. df[df['Age'] >= 18 and df['City'] == 'Jaipur']
  2. df[(df['Age'] >= 18) and (df['City'] == 'Jaipur')]
  3. df[df['Age'] >= 18 & df['City'] == 'Jaipur']
  4. df[(df['Age'] >= 18) & (df['City'] == 'Jaipur')] Correct answer.

Explanation

Combining two Series conditions requires the & operator, and each condition must be wrapped in parentheses so that comparisons are evaluated before the logical combination. The expression df[(df['Age'] >= 18) & (df['City'] == 'Jaipur')] therefore returns the rows satisfying both tests. Python's and keyword does not combine Series element-wise in this way.

Question 26Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A DataFrame df has default row labels 0, 1, 2, 3, 4. What does df.iloc[1:4] return?

  1. Rows at positions 1, 2 and 3 Correct answer.
  2. Rows with labels 1, 2, 3 and 4
  3. Rows at positions 0, 1, 2 and 3
  4. Only the row at position 1

Explanation

.iloc selects by integer position, and its slice stop value is exclusive. Thus df.iloc[1:4] returns positions 1, 2 and 3, which are three rows, not four. The row at position 4 is excluded.

Question 27Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Consider df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) and s = pd.Series([10, 20], index=['B', 'A']). What does df + s produce?

  1. An error, because the index of s does not match the row index of df
  2. Column A increased by 20 and column B increased by 10 in every row Correct answer.
  3. A DataFrame in which only column A is increased by 10
  4. A DataFrame with 10 added to every entry

Explanation

When a DataFrame is combined with a Series, pandas aligns the Series index with the DataFrame's column labels. Here s has index ['B', 'A'], so 10 is matched to column B and 20 to column A. The values are added down each column, giving A increased by 20 and B increased by 10.

Question 28Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

For a DataFrame df, a loop is written as for col, data in df.items():. What does data hold on each pass?

  1. A Series of the column's values indexed by row labels Correct answer.
  2. The column label of the current column
  3. A new DataFrame object containing only the current column
  4. A tuple containing a row label and the entire row's values

Explanation

DataFrame.items() iterates over columns and yields pairs of the form (column label, Series). The second item, data, is therefore a Series holding that column's values, indexed by the DataFrame's row labels. It is not an entire row and it is not a DataFrame.

Question 29Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A DataFrame df has five rows with default row labels. What does df.index = ['r1', 'r2', 'r3', 'r4', 'r5'] do?

  1. Replaces the row labels without changing the number of rows Correct answer.
  2. Renames only the first row label and leaves the others unchanged
  3. Adds a new column named index to df
  4. Changes the column labels to r1 through r5

Explanation

Assigning a list to df.index replaces the row labels. The list must have the same length as the number of rows, so five labels are supplied for five rows. The data values and the column labels are not changed by this assignment.

Question 30Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

What happens when pd.DataFrame({'A': [1, 2, 3]}, index=['x', 'y']) is executed?

  1. The index is automatically extended with a new label 'z'
  2. A ValueError, since index length and data length differ Correct answer.
  3. The extra value 3 is silently dropped from the column
  4. The missing third value is automatically filled with NaN

Explanation

A DataFrame built from a dictionary of lists requires any supplied index to have the same length as each column's data. Here the column has three values but the index has two labels, so pandas raises a ValueError instead of guessing. No value is dropped, filled or added automatically.

Question 31Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A Series is created with s = pd.Series({'pen': 10, 'book': 25}). What does s.index contain?

  1. [10, 25]
  2. Index(['pen', 'book'], dtype='object') Correct answer.
  3. Index([10, 25], dtype='int64')
  4. RangeIndex(start=0, stop=2, step=1)

Explanation

When a dictionary is passed to pd.Series, the dictionary keys become the Series index labels and the dictionary values become the stored data, in the same insertion order. Therefore the index is Index(['pen', 'book'], dtype='object'), not the numeric data values.

Question 32Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

After df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) is executed, what does df.shape return?

  1. (2, 3)
  2. [3, 2]
  3. (3, 2) Correct answer.
  4. 3

Explanation

The shape attribute returns a tuple in the order (number of rows, number of columns). Here the DataFrame has three rows and two columns, so df.shape is (3, 2).

Question 33Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Consider df = pd.DataFrame([{'a': 1, 'b': 2}, {'a': 3, 'c': 5}]). What is df.loc[1, 'b']?

  1. 2
  2. KeyError
  3. NaN Correct answer.
  4. 0

Explanation

Building a DataFrame from a list of dictionaries takes the union of dictionary keys as columns. Row 1 has no key 'b', so pandas fills that cell with the missing-value marker NaN rather than raising an error.

Question 34Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Let s = pd.Series([10, 20, 30, 40], index=['a', 'b', 'c', 'd']). What does s['b':'c'] return?

  1. Series([20, 30], index=['b', 'c']) Correct answer.
  2. Series([10, 20], index=['a', 'b'])
  3. Series([30, 40], index=['c', 'd'])
  4. Series([20], index=['b'])

Explanation

Slicing a Series with a string label slice is label-based, and unlike Python list slicing the stop label is included. The slice 'b':'c' therefore returns the entries at labels 'b' and 'c', with values 20 and 30.

Question 35Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

A DataFrame is created with df = pd.DataFrame({'A': [1, 2], 'B': [3, 4], 'C': [5, 6]}). What does df[['A', 'C']] return?

  1. A Series containing columns A and C
  2. A DataFrame containing only column A
  3. An error, because a list of column names is not allowed
  4. A DataFrame with columns A and C and both rows Correct answer.

Explanation

Passing a list of column labels inside the brackets selects multiple columns and returns a DataFrame, not a Series. Both rows are retained because no row filter is specified.

Question 36Data Handling using Pandas: Series and DataFrame creation, indexing, slicing, iteration, and basic operations

Consider df = pd.DataFrame({'A': [1, 2]}, index=['p', 'q']) and then df['B'] = pd.Series([5, 6], index=['q', 'p']). What does column B hold?

  1. Column B holds [NaN, NaN]
  2. Column B holds [6, 5] Correct answer.
  3. An error is raised because the index order differs
  4. Column B holds [5, 6]

Explanation

When a Series is assigned to a DataFrame column, pandas aligns the Series values by index label rather than by position. The Series has 5 at label 'q' and 6 at label 'p', so column B becomes [6, 5] for the row order p, q.

Question 37Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

Which pandas function is used to load the contents of a comma-separated values file directly into a DataFrame?

  1. pandas.load_csv()
  2. pandas.open_csv()
  3. pandas.read_csv() Correct answer.
  4. pandas.import_csv()

Explanation

pandas.read_csv() parses a delimited text file and returns a DataFrame, using the comma as the default field separator. Optional arguments such as sep, header, names and na_values control how the file is interpreted. The other three names do not exist in the pandas library.

Question 38Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

A DataFrame named df holds 12 rows and 4 columns. What does the expression df.shape return?

  1. 48
  2. (4, 12)
  3. (12, 4) Correct answer.
  4. [4, 12]

Explanation

The shape attribute of a DataFrame returns a tuple in the order (number of rows, number of columns), so a table with 12 rows and 4 columns gives (12, 4). Because it is a tuple, the values are written in round brackets, and shape[0] gives the row count while shape[1] gives the column count.

Question 39Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

Which method returns the first five rows of a DataFrame named df by default?

  1. df.first()
  2. df.top()
  3. df.peek()
  4. df.head() Correct answer.

Explanation

df.head() returns the first five rows when no argument is supplied, and an integer argument such as head(3) returns that many rows from the top. The matching method for the last rows is df.tail(). The other three method names are not defined on a pandas DataFrame.

Question 40Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

A DataFrame named df contains missing values. When df.dropna() is called with no arguments, what does it do?

  1. It replaces each missing value with the mean of its column.
  2. It removes only the rows in which every value is missing.
  3. It removes every column that contains at least one missing value.
  4. It removes every row that contains at least one missing value. Correct answer.

Explanation

The default settings of dropna() are axis=0 and how='any', so a row is discarded as soon as any one of its values is missing. To work along columns you must pass axis=1, and to drop a row only when all its values are missing you must pass how='all'. Nothing in dropna() fills values.

Question 41Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

The column df['Marks'] contains some NaN entries. Which statement replaces every missing value in that column with 0 while leaving all other columns unchanged?

  1. df['Marks'].fillna(0) Correct answer.
  2. df.fillna(axis=0)
  3. df.dropna(how='all')
  4. df['Marks'].dropna()

Explanation

Selecting the Series df['Marks'] and calling fillna(0) on it substitutes 0 wherever the value is NaN in that column only. To store the result permanently you would assign it back with df['Marks'] = df['Marks'].fillna(0). The dropna() family deletes data instead of filling it.

Question 42Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

Two DataFrames, df1 and df2, both contain a column named 'Roll'. The statement pandas.merge(df1, df2, on='Roll') is run without the how argument. Which join is performed?

  1. A right join
  2. An outer join
  3. A left join
  4. An inner join Correct answer.

Explanation

When how is not specified, merge() uses how='inner', so only the Roll values present in both DataFrames appear in the result. Rows whose key exists in only one of the two tables are discarded. The how parameter must be set to 'outer', 'left' or 'right' to obtain those other behaviours.

Question 43Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

A DataFrame named df has one numeric column 'Marks' and one text column 'Name'. What does df.describe() display by default?

  1. The number of missing values in every column of df
  2. Summary statistics for both the Marks and the Name columns
  3. Summary statistics for the numeric column Marks only Correct answer.
  4. The first five rows of the Marks and Name columns

Explanation

By default describe() works only on numeric columns and reports count, mean, standard deviation, minimum, the three quartiles and maximum. Text columns such as Name are skipped unless include='all' is passed. The method summarises values and does not display rows or missing-value counts.

Question 44Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

The statement df.to_csv('marks.csv', index=False) is executed. What is the effect of index=False?

  1. The row index labels are not written to the file. Correct answer.
  2. Only the first five rows are written to the file.
  3. Missing values are removed before the file is written.
  4. The column names are not written to the file.

Explanation

By default to_csv() writes the row index as an extra unnamed first field in every line. Setting index=False suppresses that field so the file contains only the data columns and their headers. Column headings are controlled separately by the header parameter.

Question 45Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

df.isnull().sum() is run on a DataFrame with 6 rows, and the result shows the value 2 under the column 'Fees'. What does this indicate?

  1. The Fees column contains two duplicate entries.
  2. The Fees column contains two missing values. Correct answer.
  3. The sum of the values in the Fees column is 2.
  4. Two rows were deleted from the Fees column.

Explanation

isnull() converts the DataFrame into True/False values marking where data is missing, and sum() then adds those booleans column by column because True counts as 1. A result of 2 therefore means two cells in Fees are NaN. Totalling the actual Fees values would need df['Fees'].sum().

Question 46Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

df1 has a unique key column 'Code' with the values 1, 2, 3, 4, 5, and df2 has a unique 'Code' column with the values 2, 3, 4, 6. How many rows does pandas.merge(df1, df2, on='Code', how='outer') return?

  1. 9
  2. 4
  3. 6 Correct answer.
  4. 5

Explanation

An outer join keeps every key that appears in either table, so the result contains 1, 2, 3, 4, 5 and 6, which is six rows. Keys 2, 3 and 4 have matches and are filled from both tables, while 1, 5 and 6 appear with NaN in the columns of the table that lacks them. Because the keys are unique, no combination of rows multiplies the count.

Question 47Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

The file 'sales.csv' has no header row; its first line already contains data. Which call loads the file so that pandas assigns the default column labels 0, 1, 2, ...?

  1. pd.read_csv('sales.csv', names=True)
  2. pd.read_csv('sales.csv', header=None) Correct answer.
  3. pd.read_csv('sales.csv', index_col=False)
  4. pd.read_csv('sales.csv', header=0)

Explanation

header=None tells read_csv that the file has no header row, so pandas creates default integer column labels. header=0 would consume the first data line as column names, and names expects an explicit list-like of labels rather than True. index_col does not control header parsing.

Question 48Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

A DataFrame contains NaN entries in its 'Remarks' column. Which argument to df.to_csv('out.csv') writes the text 'MISSING' in place of every NaN in the file?

  1. na_values='MISSING'
  2. null='MISSING'
  3. fillna='MISSING'
  4. na_rep='MISSING' Correct answer.

Explanation

na_rep is the to_csv parameter that sets the string used for missing values in the written file. na_values is a read_csv parameter for interpreting strings as NaN, and fillna is a DataFrame method, not a to_csv argument.

Question 49Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

Which pandas expression returns the number of students in each distinct value of the column df['City']?

  1. df['City'].value_counts() Correct answer.
  2. df['City'].count()
  3. df['City'].unique().tolist()
  4. df['City'].nunique()

Explanation

value_counts() returns a Series whose index lists each distinct value and whose data gives its frequency. count() returns only the number of non-missing entries, unique().tolist() returns the distinct values without counts, and nunique() returns the number of distinct values.

Question 50Data Handling using Pandas: importing/exporting CSV data, cleaning, joining, and descriptive statistics

df1 has one row for each Roll number 1, 2 and 3. df2 has one row for each Roll number 2, 3 and 4. What is returned by pd.merge(df1, df2, on='Roll', how='left')?

  1. Four rows: Roll 1, 2, 3 and 4 all appear
  2. Three rows; Roll 1 has NaN in df2 columns Correct answer.
  3. One row: only Roll 2 and Roll 3 match
  4. Two rows: only Roll 2 and Roll 3 appear

Explanation

A left merge keeps every key from the left DataFrame and attaches matching rows from the right DataFrame. Roll 1 is retained with NaN in the df2 columns, while Roll 4 from df2 is excluded.