Beispiel #1
0
def read_csv(path,
             engine='python',
             delimiter=',',
             na_filter=False,
             strip_col=False,
             quoting=3,
             encoding='utf-8'):
    if quoting == True:
        quoting = 0
    elif quoting == False:
        quoting = 3
    dir_data = os.getcwd() + '/data'
    path = os.path.join(dir_data, path)
    res = pd.DataFrame()
    if os.path.isfile(path):
        res = table_reader.read_csv(path, engine, delimiter, na_filter,
                                    strip_col, quoting, encoding)
    elif os.path.isdir(path):
        for f in os.listdir(path):
            if f.endswith('.csv'):
                f_path = os.path.join(path, f)
                try:
                    tmp = table_reader.read_csv(f_path, engine, delimiter,
                                                na_filter, strip_col, quoting,
                                                encoding)
                except:
                    raise BFE.from_errors([{
                        '0100':
                        'Can not read ' + f_path + '.'
                    }])
                if res.shape != (0, 0) and not res.columns.equals(tmp.columns):
                    raise BFE.from_errors([{
                        '0100':
                        'Files under ' + path + ' do not have same schema.'
                    }])
                res = pd.concat([res, tmp])
    else:
        raise BFE.from_errors([{'0100': 'Path ' + path + ' is incorrect.'}])
    for i, col in enumerate(res.columns):
        res = res.rename(
            columns={'Unnamed: {i}'.format(i=i): 'Unnamed_{i}'.format(i=i)})

    return {'table': res}
Beispiel #2
0
def read_csv(
    path,
    delimiter=',',
    na_filter=False,
    strip_col=False,
):
    dir_data = os.getcwd() + '/data'
    path = os.path.join(dir_data, path)
    return {
        'table': table_reader.read_csv(path, delimiter, na_filter, strip_col)
    }
Beispiel #3
0
def read_csv(path,
             engine='python',
             delimiter=',',
             na_filter=False,
             strip_col=False,
             quoting=3,
             encoding='utf-8'):
    if quoting == True:
        quoting = 0
    elif quoting == False:
        quoting = 3
    dir_data = os.getcwd() + '/data'
    path = os.path.join(dir_data, path)
    return {
        'table':
        table_reader.read_csv(path, engine, delimiter, na_filter, strip_col,
                              quoting, encoding)
    }
Beispiel #4
0
def read_csv(path):
    return {'table': table_reader.read_csv(path)}