KnowledgeBoat Logo
|

Informatics Practices

Which of the following commands shows the information with city="Delhi" from dataframe SHOP?

  1. print(SHOP[City == 'Delhi'])
  2. print(SHOP[SHOP.City == 'Delhi])
  3. print(SHOP[SHOP.'City' == 'Delhi'])
  4. print(SHOP[SHOP[City] == 'Delhi'])

Python Data Handling

1 Like

Answer

print(SHOP[SHOP.City == 'Delhi'])

Reason — The correct code print(SHOP[SHOP.City == 'Delhi']) filters the SHOP DataFrame to show only the rows where the City column is equal to 'Delhi'. It does this by creating a boolean mask SHOP.City == 'Delhi' that returns True for rows where the city is 'Delhi' and False otherwise, and then using this mask to select the corresponding rows from the original DataFrame using SHOP[]. The resulting DataFrame, which contains only the rows that match the condition, is then printed to the console.

Answered By

2 Likes


Related Questions