You are on page 1of 1

Consider the following DataFrame,

pid pname price


0 101 eraser 3
1 102 pen 10
2 103 scale 5
3 104 box 25

Write a python program to create the above DataFrame:

import pandas as pd

D={"pid":[101,102,103,104],"pname":["eraser","pen","scale","box"],"price":[3,10,5,25]}

df=pd.DataFrame(D)

print(df)

Write a python program to add a new column discount with value as 7% discount for all product.

df["discount"]=df['price']*.07
print(df)

pid pname price discount


0 101 eraser 3 0.21
1 102 pen 10 0.70
2 103 scale 5 0.35
3 104 box 25 1.75

Write a python program to add a new column selling _price with value as price-discount

df["selling_price"]=df['price']-df['discount']
print(df)

pid pname price discount selling_price


0 101 eraser 3 0.21 2.79
1 102 pen 10 0.70 9.30
2 103 scale 5 0.35 4.65
3 104 box 25 1.75 23.25

You might also like