Q. Given a data frame namely data as shown in adjacent table (fruit names are row labels). Write code statement to:


    Color    Count    Price
Apple    Red    3    120
Apple    Green    9    110
Pear    Red    25    125
Pear    Green    26    150
Lime    Green    99    70

(a) Find all rows with the label "Apple". Extract all columns.

(b) List fruits with count more than 25.

(c) List single True or False to signify if all prices are more than 100 or not.

(d) List 2nd, 3rd and 4th rows.


Answer :-

(a) data.loc['Apple', :]
(b) data[data[ 'Count'] >25]
(c) (data['Price'] > 100).all()
(d) data.iloc [0:3, :]

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post