def _count_header(fpath):
    """
    Detects and returns the length of the header section in a CSV file where
    the header ends with a line "data".

    :param fpath: File path [string]
    :return: length of the header [int]
    """
    with open(fpath) as reader:

        for count, line in enumerate(reader):
            if line.strip() == 'data':
                return count + 1
        else:
            raise Exception('Cannot find "data" line in file: {}'.format(fpath))