Q. Consider the dataframe data given. Using the same dataframe data, answer the following:
Color Count Price
Apple Red 3 120
Apple Green 9 110
Pear Red 25 125
Pear Green 26 150
Lime Green 99 70
(a) List only the columns Color and Price using loc.
(b) List only columns 0 and 2 (column indexes) using iloc.
(c) List only rows with labels 'Apple' and 'Pear' using loc.
(d) List only rows 1, 3, 4 using iloc.
Answer :-
(a) data.loc[:, ['Color', 'Price']]
(b) data.iloc[:, [0, 2]]
(c) data.loc [['Apple', 'Pear']]
(d) data.iloc [[1, 3, 4]]
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )