Informatics Practices
Which of the following commands shows the information with city="Delhi" from dataframe SHOP?
- print(SHOP[City == 'Delhi'])
- print(SHOP[SHOP.City == 'Delhi])
- print(SHOP[SHOP.'City' == 'Delhi'])
- 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
1 Like
Related Questions
CSV stands for :
- Column Separated Value
- Class Separated Value
- Comma Separated Value
- None of the above
Which of the following can be used to specify the data while creating a dataframe?
- Series
- List of Dictionaries
- Structured ndarray
- All of these
The following statement will …………… .
df = df.drop(['Name', 'Class', 'Rollno'], axis = 1) #df is a DataFrame object- delete three columns having labels 'Name', 'Class' and `Rollno'
- delete three rows having labels 'Name', 'Class' and 'Rollno'
- delete any three columns
- return error
Assertion (A): Pandas is a Python library.
Reasoning (R): Pandas is a powerful, flexible and easy to use open source data analysis library.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.