I have a csv file that has 3 column (product name, price, website).
product.csv
Product_name,price, website
Koko krunch,13.99,Lotus
Koko krunch,15.90,mygroser
Koko krunch,15.49,gogopasar
How do I compare the price and then display the lowest price with the product name and website? Below is my code but the result is not accurate and I think there's a better way to do it.
import pandas as pd
data = pd.read_csv("product_list.csv")
df = pd.DataFrame(data, columns= ['price'])
df = df.astype(float)
temp_product = []
temp_price = []
temp_website = []
for i in data.loc[:,'product_name']:
temp_product.append(i)
for i in df.loc[:,'price']:
temp_price.append(i)
for i in data.loc[:,'website']:
temp_website.append(i)
prices = 9999.99
temp = 0
for i in temp_price:
if i<prices:
index = temp
temp+=1
print("")
print("Product with lowest price:")
print("")
print("PRODUCT: " + temp_product[index])
print("PRICE: RM " , temp_price[index])
print("WEBSITE: " + temp_website[index])
print("")
The output of this code is PRODUCT: Koko krunch Price: RM 15.40 Website: gogopasar