""" Felix Muzny DS 2000 Lecture 11 October 15, 2024 Data file (all sept 2024 ebike trips starting at Forsyth) Three columns: - end station name - end station latitude (latitude is flatitude) - end station longitude (longitude is veritcal) Goals for today’s code: - read a csv into a list of lists - how many trips were to "Brigham Circle - Francis St at Huntington" - where did the BlueBikes riders go from NEU in September? """ # to help us read CSVs import csv FILENAME = "bluebikes_forsyth_100.csv" STATION_OF_INTEREST = "Brigham Circle - Francis St at Huntington Ave" FORSYTH_LAT = 42.339202 FORSYTH_LONG = -71.090511 STATION_COL = 0 LAT_COL = 1 LONG_COL = 2 def read_csv(filename): ''' Function: read_csv parameter: filename, a string Returns: 2d list of strings, the contents of the file ''' data = [] with open(filename, "r") as infile: csvfile = csv.reader(infile, delimiter=",") for row in csvfile: data.append(row) return data def get_station(data, station_name, col): """ Get all rows from the data where the station name :param data: list of lists of strings :param station_name: string station name to search for :param col: int column to look in for the station name :return: list of ints """ new_rows = [] for row in data: if row[col] == station_name: new_rows.append(row) return new_rows def main(): print("lec 11 - bluebikes") data = read_csv(FILENAME) print("Number of rows:", len(data)) print("First row:", data[0]) # get the rows for the station we care about station_rows = get_station(data, STATION_OF_INTEREST, STATION_COL) print("Number of trips to", STATION_OF_INTEREST, ":", len(station_rows)) main()