def get_field_freq(filename,
                   dialect,
                   field_number,
                   max_freq_size=MAX_FREQ_SIZE_DEFAULT):
    """ Collects a frequency distribution for a single field by reading
        the file provided.
        Issues:
        - has limited checking for wrong number of fields in rec
    """
    freq        = collections.defaultdict(int)
    rec_cnt     = 0
    truncated   = False
    invalid_row_cnt = 0

    for fields in csv.reader(open(filename,'r'), dialect=dialect):
        rec_cnt += 1
        if rec_cnt == 1 and dialect.has_header:
            continue
        try:
            freq[fields[field_number].strip()] += 1
        except __HOLE__:
            invalid_row_cnt += 1
        if len(freq) >= max_freq_size:
            print '      WARNING: freq dict is too large - will trunc'
            truncated = True
            break

    return freq, truncated, invalid_row_cnt
dataset/ETHPy150Open kenfar/DataGristle/gristle/field_misc.py/get_field_freq