Coverage for lingpy/read/csv.py : 96%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Module provides functions for reading csv-files. """
filename, fileformat='', dtype=None, comment='#', sep='\t', strip_lines=True, header=False ): """ Very simple function to get quick (and somewhat naive) access to CSV-files.
Parameters ---------- filename : str Name of the input file. fileformat : {None str} If not specified the file <filename> will be loaded. Otherwise, the fileformat is interpreted as the specific extension of the input file. dtype : {list} If not specified, all data will be loaded as strings. Otherwise, a list specifying the data for each line should be provided. comment : string (default="#") Comment character in the begin of a line forces this line to be ignored. sep : string (default = "\t") Specify the separator for the CSV-file. strip_lines : bool (default=True) Specify whether empty "cells" in the input file should be preserved. If set to c{False}, each line will be stripped first, and all whitespace will be cleaned. Otherwise, each line will be separated using the specified separator, and no stripping of whitespace will be carried out. header : bool (default=False) Indicate, whether the data comes along with a header.
Returns ------- l : list A list-representation of the CSV file.
""" # check for correct fileformat else:
# open the file
# check for header
else: else:
filename, fileformat=None, dtype=None, comment='#', sep='\t', strip_lines=True, header=False ): """ Very simple function to get quick access to CSV-files.
Parameters ---------- filename : str Name of the input file. fileformat : {None str} If not specified the file <filename> will be loaded. Otherwise, the fileformat is interpreted as the specific extension of the input file. dtype : {None list} If not specified, all data will be loaded as strings. Otherwise, a list specifying the data for each line should be provided. comment : string (default="#") Comment character in the begin of a line forces this line to be ignored. sep : string (default = "\t") Specify the separator for the CSV-file. strip_lines : bool (default=True) Specify whether empty "cells" in the input file should be preserved. If set to c{False}, each line will be stripped first, and all whitespace will be cleaned. Otherwise, each line will be separated using the specified separator, and no stripping of whitespace will be carried out. header : bool (default=False) Indicate, whether the data comes along with a header.
Returns ------- d : dict A dictionary-representation of the CSV file, with the first row being used as key and the rest of the rows as values. """
""" Function reads a csv-file into a multi-dimensional dictionary structure. """
infile, family='Indo-European', classification='hh', max_synonyms=2, min_population=lambda x: x > 0 or abs(x) > 1900, merge_vowels=True, evaluate=False ): # read in all data
# find the data confirming to selection, get the header for the # classification first
# check for family type
# index the classification index a, b = classification.split(',') clsA_idx = header.index(a) cls_idx = (clsA_idx, clsB_idx) else:
# create dictionary to store the data
# lats / longs coords={}, iso={}, population={}, classification=dict( hammarstroem={}, ethnologue={}, wals={}, wals_genus={} ) )
# iterate over data and extract the lines
# check for population # append data to meta
e.strip() and 'xxx' not in e.lower()][:max_synonyms]
else: |