Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multiplying two columns in pandas

I have two columns, which are unit price and quantity (through input by user) and I have to multiply them together to get the total price.

price="{:0.2f}".format(float(input("Enter price: ")))
quantity=int(input("Enter quantity: "))
print("Enter expired date: ")
year = int(input('Enter a year'))
                            
                            
month = int(input('Enter a month'))
            
day = int(input('Enter a day'))
expired_date = datetime.date(year, month, day)
       
df1 = pd.DataFrame(data=[[name,price,quantity,expired_date,today<=expired_date]],columns=["Name","Unit Price","Quantity","Expiry Date","Expired?"])
            

df = df.append(df1,ignore_index=True)
            
**df['Price'] = (df["Quantity"]*(df["Unit Price"]))**
            
df["Expired?"] = df["Expired?"].replace({True: 'Yes', False: 'No'})

However, the result I get is as follows:

Unit Price   Quantity     Price 
  2.00       2            2.002.00

What is the solution for this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should not format your price as a string, here:

price = "{:0.2f}".format(float(input("Enter price: ")))

Just leave

price = float(input("Enter price: "))

and that should handle your multiplication correctly

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading