I can't figure out what the error is in my case when creating an argument via add_file_arg() for mrjob. I'm trying to pass names from csv to my mapper and find attributes for each name in the mapper.
This is my code so far:
from mrjob.job import MRJob
from mrjob.step import MRStep
class MRFlight(MRJob):
def configure_args(self):
super(MRFlight,self).configure_args()
self.add_file_arg('--airlines')
def steps(self):
return [
MRStep(mapper=self.mapper,
reducer_init=self.reducer_init,
reducer=self.reducer)
]
def mapper(self, _, line):
(year, month, day, day_of_week, airline, flight_number, tail_number, origin_airport, destination_airport,
scheduled_departure, departure_time, departure_delay, taxi_out, wheels_off, scheduled_time, elapsed_time,
air_time, distance, wheels_on, taxi_in, scheduled_arrival, arrival_time, arrival_delay, diverted, cancelled,
cancellation_reason, air_system_delay, security_delay, airline_delay, late_aircraft_delay,
weather_delay) = line.split(',')
yield airline, int(cancelled)
def reducer_init(self):
self.airlines_name = {}
with open('airlines.csv', 'r') as file:
for line in file:
code, full_name = line.split(',')
full_name = full_name[:-1]
self.airlines_name[code]= full_name
def reducer(self,key,values):
total = 0
num_rows = 0
for value in values:
total += value
num_rows +=1
yield key,total/num_rows
if __name__ == '__main__':
MRFlight.run()`
I get such an error:
usage: 07_cancellation_rate_by_airilne.py [options] [input files]
07_cancellation_rate_by_airilne.py: error: unrecognized arguments: --airilines airlines.csv