'I'm working with this CSV file, and I need help finding the minimum price offered by a company on any of their models

For example, in the attached screenshot, Alfa Romeo's lowest price would be 13495, Audi's would be 13950, and so on. Though in this snap, the lowest price is at the top for each company, but in the full file, there are many instances where the lowest is located randomly. Any help would be appreciated!
Solution 1:[1]
I would be easier to help if you could share the csv file but here is something that migth help.
You can read csv file like this
import csv
with open('file.csv', newline='') as f:
reader = csv.reader(f)
data = list(reader)
Now you have the data in "data" named list. You should use dict to find the lowest price. Next example finds the best price to one company. If you like to make it more specific just change the key.
company_price_dict = {}
for line in data:
if line[1] not in company_price_dict:
company_price_dict[line[1]] = line[-1]
# if you want more specific you can try this
# company_price_dict[line[1]+line[2]+line[3] etc..]
elif line[-1] < company_price_dict[line[1]]:
company_price_dict[line[1]] = line[-1]
Finally you can find the lowest price to any given car company like this.
car_price = company_price_dict["audi"] # or "audisedan... etc."
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
