Q. Create a Data Frame QtrSales where each row contains the item category, item name, and expenditure. Locate the 3 largest values of Expenditure in this data frame.
Answer :-
import pandas as pd QtrSales = pd.DataFrame({ "Item Category":['A', 'B', 'A', 'A', 'B', 'C', 'B', 'C'], 'Item Name': ['iPad', 'LCD', 'iPhone', 'iWatch', 'Projector', 'Hard disk', 'Smartboard', 'Pen drive'], 'Expenditure': [288000, 356000, 497000, 315000, 413000, 45000, 211000, 21000]}) print("Dataframe QtrSales is:") print (QtrSales) print(" 3 largest expenditure values in given dataframe are:" ) print(QtrSales.sort_values ("Expenditure", ascending = False).head(3))
Output :-
Dataframe QtrSales is:
Item Category Item Name Expenditure
0 A iPad 288000
1 B LCD 356000
2 A iPhone 497000
3 A iWatch 315000
4 B Projector 413000
5 C Hard disk 45000
6 B Smartboard 211000
7 C Pen drive 21000
3 largest expenditure values in given dataframe are:
Item Category Item Name Expenditure
2 A iPhone 497000
4 B Projector 413000
1 B LCD 356000
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )