numpy——genfromtext

import numpy
print(help(numpy.genfromtxt))

genfromtxt(fname, dtype=<class 'float'>, comments='#', delimiter=None, skip_header=0, skip_footer=0, converters=None, missing_values=None, filling_values=None, usecols=None, names=None, excludelist=None, deletechars=None, replace_space='_', autostrip=False, case_sensitive=True, defaultfmt='f%i', unpack=None, usemask=False, loose=True, invalid_raise=True, max_rows=None, encoding='bytes')
----------
fname : file, str, pathlib.Path, list of str, generator File, filename, list, or generator to read. If the filename  extension is `.gz` or `.bz2`, the file is first decompressed. Note that generators must return byte strings in Python 3k. The strings in a list or produced by a generator are treated as lines. ##文件路径
dtype : dtype, optional Data type of the resulting array. If None, the dtypes will be determined by the contents of each column, individually. ##文件数据类型,如果没有指定则依据每列的内容分别设定
comments : str, optional The character used to indicate the start of a comment. All the characters occurring on a line after a comment are discarded ##跳过注释
delimiter : str, int, or sequence, optional The string used to separate values. By default, any consecutive whitespaces act as delimiter. An integer or sequence of integers can also be provided as width(s) of each field. ##分隔符或者字段长度
skiprows : int, optional `skiprows` was removed in numpy 1.10. Please use `skip_header` instead. ##不再使用
skip_header : int, optional The number of lines to skip at the beginning of the file. ##跳过前n行获取数据
skip_footer : int, optional The number of lines to skip at the end of the file. ##跳过后n行获取数据
converters : variable, optional The set of functions that convert the data of a column to a value. The converters can also be used to provide a default value for missing data: ``converters = {3: lambda s: float(s or 0)}``.##数据转换器如将%转化成小数。
missing : variable, optional `missing` was removed in numpy 1.10. Please use `missing_values` instead.
missing_values : variable, optional The set of strings corresponding to missing data.##将特定值表示成缺失值
filling_values : variable, optional The set of values to be used as default when the data are missing. ##缺失值补缺
usecols : sequence, optional Which columns to read, with 0 being the first. For example, ``usecols = (1, 4, 5)`` will extract the 2nd, 5th and 6th columns. ##获取感兴趣的列
names : {None, True, str, sequence}, optional If `names` is True, the field names are read from the first line after the first `skip_header` lines. This line can optionally be proceeded  by a comment delimiter. If `names` is a sequence or a single-string of comma-separated names, the names will be used to define the field names in a structured dtype. If `names` is None, the names of the dtype fields will be used, if any. ##给列命名
excludelist : sequence, optional A list of names to exclude. This list is appended to the default list ['return','file','print']. Excluded names are appended an underscore: for example, `file` would become `file_`.##过滤掉特定列
deletechars : str, optional A string combining invalid characters that must be deleted from the names.##非法字符过滤
defaultfmt : str, optional A format used to define default field names, such as "f%i" or "f_%02i".
autostrip : bool, optional Whether to automatically strip white spaces from the variables. ##分列时每项默认不会删除前后的空格。autostrip=True,会处理掉前后空格。
replace_space : char, optional Character(s) used in replacement of white spaces in the variables names. By default, use a '_'.
case_sensitive : {True, False, 'upper', 'lower'}, optional If True, field names are case sensitive. If False or 'upper', field names are converted to upper case. If 'lower', field names are converted to lower case.##转化大小写 case_sensitive = False 大写,true小写
unpack : bool, optional If True, the returned array is transposed, so that arguments may be unpacked using ``x, y, z = loadtxt(...)``
usemask : bool, optional If True, return a masked array. If False, return a regular array.
loose : bool, optional If True, do not raise errors for invalid values. invalid_raise : bool, optional If True, an exception is raised if an inconsistency is detected in the number of columns. If False, a warning is emitted and the offending lines are skipped.
max_rows : int, optional The maximum number of rows to read. Must not be used with skip_footer at the same time. If given, the value must be at least 1. Default is to read the entire file.
encoding : str, optional Encoding used to decode the inputfile. Does not apply when `fname` is a file object. The special value 'bytes' enables backward compatibility workarounds that ensure that you receive byte arrays when possible and passes latin1 encoded strings to converters. Override this value to receive unicode arrays and pass strings as input to converters. If set to None the system default is used. The default value is 'bytes'.

Notes
-----
* When spaces are used as delimiters, or when no delimiter has been given
as input, there should not be any missing data between two fields.
* When the variables are named (either by a flexible dtype or with `names`,
there must not be any header in the file (else a ValueError
exception is raised).
* Individual values are not stripped of spaces by default.
When using a custom converter, make sure the function does remove spaces.

posted @ 2020-10-14 14:02  大威1030  阅读(159)  评论(0)    收藏  举报