def readtable(filename, **kwargs): ''' Create table by reading column oriented data from a file. :param filename: (*string*) File name for reading. :param delimiter: (*string*) Variable delimiter character. Default is ``None``, means space or tab delimiter. :param format: (*string*) Colomn format of the file. Default is ``None``, means all columns were read as string variable. ``%s``: string; ``%i``: integer; ``%f``: float; ``%{yyyyMMdd...}D``: date time. :param headerlines: (*int*) Lines to skip at beginning of the file. Default is ``0``. The line after the skip lines will be read as variable names of the table. the ``headerlines`` should set as ``-1`` if there is no field name line at beginning of the file. :param encoding: (*string*) Character encoding scheme associated with the file. Default is ``UTF8``. :param varnames: (*string*) Specified variable names for the readed table. Default is ``None``, means the variable names should be read from the file. :param readvarnames: (*boolean*) Read variable names or not. Default is ``True``. :param readrownames: (*boolean*) Read row names or not. Default is ``False``. :returns: (*PyTableData*) The table. ''' delimiter = kwargs.pop('delimiter', None) format = kwargs.pop('format', None) headerlines = kwargs.pop('headerlines', 0) encoding = kwargs.pop('encoding', 'UTF8') readvarnames = kwargs.pop('readvarnames', True) readrownames = kwargs.pop('readrownames', False) tdata = TableUtil.readASCIIFile(filename, delimiter, headerlines, format, encoding, readvarnames) r = PyTableData(tdata) varnames = kwargs.pop('colnames', None) varnames = kwargs.pop('varnames', varnames) if not varnames is None: r.setcolnames(varnames) return r
def addfield(self, fieldname, dtype, values=None): dt = TableUtil.toDataTypes(dtype) self.layer.editAddField(fieldname, dt) if not values is None: n = self.shapenum() for i in range(n): if i < len(values): self.layer.editCellValue(fieldname, i, values[i])
def readtable(filename, **kwargs): ''' Create table by reading column oriented data from a file. :param filename: (*string*) File name for reading. :param delimiter: (*string*) Variable delimiter character. Default is ``None``, means space or tab delimiter. :param format: (*string*) Colomn format of the file. Default is ``None``, means all columns were read as string variable. ``%s``: string; ``%i``: integer; ``%f``: float; ``%{yyyyMMdd...}D``: date time. :param headerlines: (*int*) Lines to skip at beginning of the file. Default is ``0``. The line after the skip lines will be read as variable names of the table. the ``headerlines`` should set as ``-1`` if there is no field name line at beginning of the file. :param encoding: (*string*) Character encoding scheme associated with the file. Default is ``UTF8``. :param varnames: (*string*) Specified variable names for the readed table. Default is ``None``, means the variable names should be read from the file. :param readvarnames: (*boolean*) Read variable names or not. Default is ``True``. :param readrownames: (*boolean*) Read row names or not. Default is ``False``. :param usecols: (*list*) Return a subset of the columns. If list-like, all elements must either be positional (i.e. integer indices into the document columns) or strings that correspond to column names provided either by the user in names or inferred from the document header row(s). :returns: (*PyTableData*) The table. ''' delimiter = kwargs.pop('delimiter', None) format = kwargs.pop('format', None) headerlines = kwargs.pop('headerlines', 0) encoding = kwargs.pop('encoding', 'UTF8') readvarnames = kwargs.pop('readvarnames', True) readrownames = kwargs.pop('readrownames', False) usecols = kwargs.pop('usecols', None) if usecols is None: tdata = TableUtil.readASCIIFile(filename, delimiter, headerlines, format, encoding, readvarnames) else: tdata = TableUtil.readASCIIFile(filename, delimiter, headerlines, format, encoding, readvarnames, usecols) r = PyTableData(tdata) varnames = kwargs.pop('colnames', None) varnames = kwargs.pop('varnames', varnames) if not varnames is None: r.setcolnames(varnames) return r
def addcol(self, colname, dtype, index=None): ''' Add an emtpy column. :param colname: (*string*) The new column name. :param dtype: (*string*) The data type. [string | int | float]. :param index: (*int*) The order index of the column to be added. Default is ``None``, the column will be added as last column. ''' dtype = TableUtil.toDataTypes(dtype) if index is None: self.data.addColumn(colname, dtype) else: self.data.addColumn(index, colname, dtype)
def addfield(self, fieldname, dtype, values=None): ''' Add a field into the attribute table. :param fieldname: (*string*) Field name. :param dtype: (*string*) Field data type [string | int | float | double]. :param values: (*array_like*) Field values. ''' dt = TableUtil.toDataTypes(dtype) self.layer.editAddField(fieldname, dt) if not values is None: n = self.shapenum() for i in range(n): if i < len(values): self.layer.editCellValue(fieldname, i, values[i])