KnowledgeBoat Logo
|
LoginJOIN NOW

Informatics Practices

Assertion (A): After running the following code:

df = pd.DataFrame([11,46], index = ['True', 'False'])
print(df[True])

A key error will be produced.

Reasoning (R): Dataframe does not support Boolean Indexing.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Python Data Handling

1 Like

Answer

A is true but R is false.

Explanation
DataFrames do support Boolean Indexing, which allows to select rows based on a Boolean condition. The code df[True] is trying to access a column named True, which does not exist in the DataFrame. The index of the DataFrame is ['True', 'False']. To access the row where the index is 'True', we would use df.loc['True']. This is an example of label-based indexing, where we are selecting a row based on its index label.

Answered By

1 Like


Related Questions