""" John Rachlin DS 2000: Intro to Programming with Data Date: Thu Oct 27 19:14:37 2022 File: reading.py Description: """ import dataproc as dp def main(): data = dp.read_table('sample.csv', coltypes=[str,str,float]) sales = dp.extract_column(data, 2) print(sales) datadict = dp.read_table_to_dict('sample.csv', coltypes=[str,str,float]) sales2 = dp.extract_column(datadict, 'sales') print(sales2) #duration,start_day,start_day_name,start_station,end_station,bike_id #602,23,Friday,MIT Vassar St,Packard's Corner - Commonwealth Ave at Brighton Ave,8250 trips = dp.read_table_to_dict('trips_small.csv', coltypes=[int, int, str, str, str, int]) #for trip in trips: # print(trip) # Now you don't need to keep track of column positions print(trips[0]) print(trips[0]['start_station']) # Extract days of the week dow = dp.extract_column(trips, 'start_day_name') #print(dow) # Average trip duration durations = dp.extract_column(trips, 'duration') #print("Average trip duration: ", dp.avg(durations)) # Trip duration histogram import matplotlib.pyplot as plt plt.hist(durations, bins=50) if __name__ == '__main__': main()