KnowledgeBoat Logo
|

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