Home > Mobile >  Looking for Simple Python Help: Counting the Number of Vehicles in a CSV by their Fuel Type
Looking for Simple Python Help: Counting the Number of Vehicles in a CSV by their Fuel Type

Time:11-20

plt.savefig("temp.png")

CodePudding user response:

You mentioned it's a CSV specifically. Read in the file line by line, split the data by comma (which produces a list for the current row), then if currentrow[3] == fuel type increment your count.

Example:

gas_cars=0
with open("data.csv", "r") as file:
    for line in file:
        row = line.split(",")
        if row[3] == "Gasoline":
            gas_cars  = int(row[6]) # num cars for that car make
        # ...
        # ...
        # ...
  • Related