0% found this document useful (0 votes)
77 views4 pages

Import CSV

This Python script analyzes border crossing transportation data from a CSV file from 2000-2012. It loads the data into lists and provides a menu interface to: 1) display bus passengers in 2008, 2) calculate statistics for different transport modes from 2002-2009, 3) find years above the 13-year mean for different modes, 4) create plots of bus passengers vs year and personal vehicles vs year. The script contains functions to handle the menu options and analysis calculations.

Uploaded by

elginlol13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views4 pages

Import CSV

This Python script analyzes border crossing transportation data from a CSV file from 2000-2012. It loads the data into lists and provides a menu interface to: 1) display bus passengers in 2008, 2) calculate statistics for different transport modes from 2002-2009, 3) find years above the 13-year mean for different modes, 4) create plots of bus passengers vs year and personal vehicles vs year. The script contains functions to handle the menu options and analysis calculations.

Uploaded by

elginlol13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import csv

import [Link] as plt;

years = []
Bus_Passengers = []
Buses = []
Personal_vehicles = []
Loaded_Trucks = []

with open('brdrxingusc_dataset.csv', 'r') as csv_file:


csv_reader = [Link](csv_file)
csv_reader = zip(*csv_reader)
for row in csv_reader:
[Link](row[0])
Bus_Passengers.append(row[1])
[Link](row[2])
Personal_vehicles.append(row[3])
Loaded_Trucks.append(row[4])

loop = True
def menu():

print("=====================================================================")
print('[Link] display the number of Bus Passenger crossing the border in
2008, ')
print('2. Of the users selected type of the border-crossing transport,
display')
print(' a) the mean number of the vehicles in that transport mode for
the 8-year span of 2002 to 2009.')
print(' b) the maximum number of vehicles in that transport mode in that
period and the year that the maximum occurs.')
print('3. Of the users selected type of the border-crossing transport, find
the mean number of vehicles for the whole 13-year period. Display the number of
vehicles in that transport mode and the corresponding years that are higher than
the mean value.')
print('4. Make the following plots')
print(' a) Average number of Bus Passengers per Bus vs Year as a line
plot.')
print(' b) Number of Personal Vehicles vs Year as a bar chart.')
print('5. Press "Q" or "q" to Exit Programme')

print("=====================================================================")

option = input(': ')


if option == '1':
buspassenger2008()
elif option == '2':
eightyearbordercrossing()
elif option == '3':
thirteenyearbordercrossing()
elif option == '4':
plot()
elif option == 'Q' or option == 'q':
print('Goodbye')
loop = False
else:
print('Invalid choice. Please try again.')
def buspassenger2008():
print('The number of Bus Passenger crossing the border in 2008 is',
Bus_Passengers[9])

def eightyearbordercrossing():
vehicle = int(input('Please select the mode of transport,\n1 for Buses\n2 for
Personal Vehicles\n3 for Loaded Trucks\n: '))
if vehicle == 1:
i = 3
j = 0
m = 0
while i <= 10:
j=j+int(Buses[i])
if m <= int(Buses[i]):
m = int(Buses[i])
y = int(years[i])
else:
break
i=i+1
mean = j/8
print('The mean number of the vehicles Buses for the 8-year span of 2002 to
2009 is ', mean)
print('The year with the max number of Buses crossing is ', y)
print('The max number of the vehicles Buses for that year is ', m)

elif vehicle == 2:
i = 3
j = 0
m = 0
while i <= 10:
j=j+int(Personal_vehicles[i])
if m <= int(Personal_vehicles[i]):
m = int(Personal_vehicles[i])
y = int(years[i])
else:
break
i=i+1
mean = j/8
print('The mean number of the vehicles Personal Vehicles for the 8-year
span of 2002 to 2009 is ', mean)
print('The year with the max number of Personal Vehicles crossing is ', y)
print('The max number of the vehicles Personal Vehicles for that year is ',
m)
elif vehicle == 3:
i = 3
j = 0
m = 0
while i <= 10:
j=j+int(Loaded_Trucks[i])
if m <= int(Loaded_Trucks[i]):
m = int(Loaded_Trucks[i])
y = int(years[i])
else:
break
i=i+1
mean = j/8
print('The mean number of the vehicles Loaded Trucks for the 8-year span of
2002 to 2009 is ', mean)
print('The year with the max number of Loaded Trucks crossing is ', y)
print('The max number of the vehicles Loaded Trucks for that year is ', m)

else:
print('Error')

def thirteenyearbordercrossing():
vehicle = int(input('Please select the mode of transport,\n1 for Buses\n2 for
Personal Vehicles\n3 for Loaded Trucks\n: '))
if vehicle == 1:
i = 1
j = 0
while i <= 12:
j=j+int(Buses[i])
i=i+1
mean = j/13
print('The mean number of the vehicles Buses for the 13-year span of 2000
to 2012 is ', mean)
while i >= 12:
if mean <=int(Buses[i]):
print('The year ', years[i], 'is higher than the mean')
print('The number of the vehicles Buses for that year is ',
int(Buses[i]))
i=i-1
elif vehicle == 2:
i = 1
j = 0
while i <= 12:
j=j+int(Personal_vehicles[i])
i=i+1
mean = j/13
print('The mean number of the vehicles Personal Vehicles for the 13-year
span of 2000 to 2012 is ', mean)
while i >= 12:
if mean <=int(Personal_vehicles[i]):
print('The year ', years[i], 'is higher than the mean')
print('The number of the vehicles Personal Vehicles for that year
is ', int(Personal_vehicles[i]))
i=i-1
elif vehicle == 3:
i = 1
j = 0
while i <= 12:
j=j+int(Loaded_Trucks[i])
i=i+1
mean = j/13
print('The mean number of the vehicles Loaded Trucks for the 13-year span
of 2000 to 2012 is ', mean)
while i >= 12:
if mean <=int(Loaded_Trucks[i]):
print('The year ', years[i], 'is higher than the mean')
print('The number of the vehicles Loaded Trucks for that year is ',
int(Loaded_Trucks[i]))
i=i-1
else:
print('Error')

def plot():
# Plotting Number of Personal Vehicles vs Year as a bar chart
Bus_Passengers.pop(0)
[Link](0)
[Link](years, Personal_vehicles)
[Link]("Year")
[Link](rotation = 30)
[Link]("Number of Personal Vehicles")
[Link]("Number of Personal Vehicles vs Year")
[Link]()

while loop:
menu()

You might also like