Informatics Practices
Consider the dataframe SHOP given below:
Item Qty City Price
101 Biscuit 100 Delhi 10
102 Jam 110 Kolkata 25
103 Coffee 200 Kolkata 55
104 Sauce 56 Mumbai 55
105 Chocolate 170 Delhi 25
Write commands to:
(i) Write short code to show the information having city = "Delhi".
(ii) Calculate Qty * Price and assign to column 'Net_Price'.
(iii) Display Items of all rows.
Python Pandas
2 Likes
Answer
(i)
info = SHOP[SHOP['City'] == 'Delhi']
print(info)
Output
Item Qty City Price
101 Biscuit 100 Delhi 10
105 Chocolate 170 Delhi 25
(ii)
SHOP['Net_Price'] = SHOP['Qty'] * SHOP['Price']
print(SHOP)
Output
Item Qty City Price Net_Price
101 Biscuit 100 Delhi 10 1000
102 Jam 110 Kolkata 25 2750
103 Coffee 200 Kolkata 55 11000
104 Sauce 56 Mumbai 55 3080
105 Chocolate 170 Delhi 25 4250
(iii)
items = SHOP['Item']
print(items)
Output
101 Biscuit
102 Jam
103 Coffee
104 Sauce
105 Chocolate
Name: Item, dtype: object
Answered By
2 Likes
Related Questions
Prerna received an email from her bank stating that there is a problem with her account. The email provides instructions and a link, by clicking on which she can log in to her account and fix the problem. Help Prerna by telling her the precautions she should take when she receives these types of emails.
Write the names of any two common types of Intellectual Property Rights which are protected by law.
Consider the following table named "Student":
RollNo Name Marks Grade Fees Stream 1 Mishra 30 C 6000 Commerce 2 Gupta 48 B 15000 Arts 3 Khan 66 A 4800 Science 4 Chaddha 24 C 12500 Commerce 5 Yadav 23 A 10000 Arts Write the SQL functions which will perform the following operations:
(i) To show the sum of fees of all students.
(ii) To display maximum and minimum marks.
(iii) To count different types of grades available.
(iv) Write a query to count grade-wise total number of students.
(i) Consider the dataframe "EMP":
Name Basic Da Hra E1 Sanya 9500 3000 2000 E2 Krish 7000 5000 1900 E3 Rishav 9650 1500 2100 E4 Deepak 7500 2000 2700 E5 Kriti 9200 1800 500Give the output
EMP.iloc[1, 2]=8000 EMP.Hra = EMP.Hra + 200 print(EMP)(ii) Write a Python statement to change the name 'Rishav' to 'Rishab' in the above dataframe.
Or
(Option for part ii only)
Write a Python statement to calculate the sum of Basic, Da, and Hra and assign it to the column 'Salary'.