#NEWLINE# def main( ) : #NEWLINE# #INDENT# 'Main function that is called when datacleaner is run on the command line' #NEWLINE# parser = argparse . ArgumentParser ( description = 'A Python tool that automatically cleans data sets and readies them for analysis' ) #NEWLINE# parser . add_argument ( 'INPUT_FILENAME' , type = str , help = 'File name of the data file to clean' ) #NEWLINE# parser . add_argument ( '-cv' , action = 'store' , dest = 'CROSS_VAL_FILENAME' , default = None , type = str , help = 'File name for the validation data set if performing cross-validation' ) #NEWLINE# parser . add_argument ( '-o' , action = 'store' , dest = 'OUTPUT_FILENAME' , default = None , type = str , help = 'Data file to output the cleaned data set to' ) #NEWLINE# parser . add_argument ( '-cvo' , action = 'store' , dest = 'CV_OUTPUT_FILENAME' , default = None , type = str , help = 'Data file to output the cleaned cross-validation data set to' ) #NEWLINE# parser . add_argument ( '-is' , action = 'store' , dest = 'INPUT_SEPARATOR' , default = '\t' , type = str , help = 'Column separator for the input file(s) (default: \\t)' ) #NEWLINE# parser . add_argument ( '-os' , action = 'store' , dest = 'OUTPUT_SEPARATOR' , default = '\t' , type = str , help = 'Column separator for the output file(s) (default: \\t)' ) #NEWLINE# parser . add_argument ( '--drop-nans' , action = 'store_true' , dest = 'DROP_NANS' , default = False , help = 'Drop all rows that have a NaN in any column (default: False)' ) #NEWLINE# parser . add_argument ( '--ignore-update-check' , action = 'store_true' , dest = 'IGNORE_UPDATE_CHECK' , default = False , help = 'Do not check for the latest version of datacleaner (default: False)' ) #NEWLINE# parser . add_argument ( '--version' , action = 'version' , version = 'datacleaner v{version}' . format ( version = __version__ ) ) #NEWLINE# args = parser . parse_args ( ) #NEWLINE# input_data = pd . read_csv ( args . INPUT_FILENAME , sep = args . INPUT_SEPARATOR ) #NEWLINE# if ( args . CROSS_VAL_FILENAME is None ) : #NEWLINE# #INDENT# clean_data = autoclean ( input_data , drop_nans = args . DROP_NANS , ignore_update_check = args . IGNORE_UPDATE_CHECK ) #NEWLINE# if ( args . OUTPUT_FILENAME is None ) : #NEWLINE# #INDENT# print ( 'Cleaned data set:' ) #NEWLINE# print ( clean_data ) #NEWLINE# print ( '' ) #NEWLINE# print ( 'If you cannot view the entire data set, output it to a file instead. Type datacleaner --help for more information.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# clean_data . to_csv ( args . OUTPUT_FILENAME , sep = args . OUTPUT_SEPARATOR , index = False ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( args . OUTPUT_FILENAME is not None ) and ( args . CV_OUTPUT_FILENAME is None ) ) : #NEWLINE# #INDENT# print ( 'You must specify both output file names. Type datacleaner --help for more information.' ) #NEWLINE# return #NEWLINE# #UNINDENT# cross_val_data = pd . read_csv ( args . CROSS_VAL_FILENAME , sep = args . INPUT_SEPARATOR ) #NEWLINE# ( clean_training_data , clean_testing_data ) = autoclean_cv ( input_data , cross_val_data , drop_nans = args . DROP_NANS , ignore_update_check = args . IGNORE_UPDATE_CHECK ) #NEWLINE# if ( args . OUTPUT_FILENAME is None ) : #NEWLINE# #INDENT# print ( 'Cleaned training data set:' ) #NEWLINE# print ( clean_training_data ) #NEWLINE# print ( '' ) #NEWLINE# print ( 'Cleaned testing data set:' ) #NEWLINE# print ( clean_testing_data ) #NEWLINE# print ( '' ) #NEWLINE# print ( 'If you cannot view the entire data set, output it to a file instead. Type datacleaner --help for more information.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# clean_training_data . to_csv ( args . OUTPUT_FILENAME , sep = args . OUTPUT_SEPARATOR , index = False ) #NEWLINE# clean_testing_data . to_csv ( args . OUTPUT_FILENAME , sep = args . OUTPUT_SEPARATOR , index = False )