def generate_answers(): try: raw_data = pd.read_csv('DOHMH_New_York_City_Restaurant_Inspection_Results.csv',low_memory=False) except IOError: sys.exit() print "The program has got the raw data. Now it is cleaning the data... Please wait." raw_data_cleaning = data_clean.clean(raw_data) cleaned_data = raw_data_cleaning.clean_data() # question 4: compute the performance of all restaurants and print the sum for different Boroughs. print "Computing the performance of all restaurants..." grade_analysis_functions.print_restaurant_grades_all(cleaned_data) print "Camputing the performance of restaurants in different boroughs..." grade_analysis_functions.print_restaurant_grades_by_borough(cleaned_data) # question 5: generate the graphs print "Generating the graphs..." df_whole_city = grade_analysis_functions.get_grade_count_values(cleaned_data) graph_plot.generate_graph(df_whole_city,'nyc') for boroname in cleaned_data['BORO'].unique(): graph_plot.generate_graph(grade_analysis_functions.get_grade_count_values(cleaned_data[cleaned_data['BORO'] == boroname]),boroname.lower()) print "The graphs have been generated. Please check the current directory. Thanks!"
def start_analyse_grade(): print "*******************************************************************" print "This is a program to analyse the grade of restaurants in NY. " print "Make sure the csv data file is placed under the current directory. " print "Several functions may take a bit long time, thank you for your patience." print "*******************************************************************" print "Reading the data, please wait..." try: raw_data = pd.read_csv('DOHMH_New_York_City_Restaurant_Inspection_Results.csv',low_memory=False) except IOError: print "Can not open the data file, please put the DOHMH_New_York_City_Restaurant_Inspection_Results.csv datafile under the current directory " sys.exit() print "Cleaning the data, please wait..." data_process_instance = data_processing.Clean_Raw_Data(raw_data) #create an instance to get the cleaned data cleaned_data = data_process_instance.get_cleaned_data() try: #Q4:print the results of sum of the function results(all restaurants and restaurants by borough) print "Calculating the score all restaurants, it takes a bit long(more than 40s in my laptop),please wait..." grade_analysis_functions.print_restaurant_grades_all(cleaned_data) print "Calculating the score of restaurants by borough,please wait..." grade_analysis_functions.print_restaurant_grades_by_borough(cleaned_data) except KeyError: print "KeyError happens when use grade_analysis_functions" command = raw_input('if you want to contiue, please enter yes, otherwise will exit the program') if command!= 'yes': sys.exit() for boroname in cleaned_data['BORO'].unique(): print "Generating the grade number satistics graph over time in "+boroname+ " ..." plotgraph.generate_line_graph(grade_analysis_functions.get_grade_count_values(cleaned_data[cleaned_data['BORO'] == boroname]),boroname.lower()) print "Generating the grade number satistics graph over time in New York City..." df_whole_city = grade_analysis_functions.get_grade_count_values(cleaned_data) plotgraph.generate_line_graph(df_whole_city,'nyc') print "All the 6 graphs are generated and saved, thanks for using"