Ejemplo n.º 1
0
    ''' Saves cleaned data in a new Excel sheet '''
    with pd.ExcelWriter('cleaned.xlsx') as writer:
        DP.get_df().to_excel(writer, sheet_name='Clean Data')
    print('Preprocessed data excel spreadsheet created: cleaned.xlsx!')

    # Currency Conversion
    if args.currency:
        ''' Currency conversion to USD, but if second argument is added to the constructor below, it converts to any other currency'''
        CC = CurrencyConverter(DP.get_df())
        ''' Converts all columns of type float64 to the specified currency above '''
        CC.convert_all('float64')
        ''' Save converted data in a new Excel sheet '''
        with pd.ExcelWriter('converted.xlsx') as writer:
            DP.get_df().to_excel(writer,
                                 sheet_name='Converted Currency To {}'.format(
                                     CC.get_currency()))
        print('Currency conversion excel spreadsheet created: converted.xlsx!')

    # Outlier Detection
    if args.outliers:
        DO = OutlierDetector(DP.get_df())
        ''' Computes Tukey outlier upper/lower inner/outer ranges '''
        DO.compute_ranges([
            'Material Cost', 'Blending Cost', 'Production Cost',
            'Transportation Cost', 'Duty Cost', 'Total Cost'
        ])
        ''' 
            Adds a style to the dataframe which has the outlier cells coloured in 4 different colours, 
            depending on the range the outlier falls in
        '''
        outliers_df = DP.get_df().style.apply(DO.highlight_outlier_cells,