]])
# 设置注释的标识符,默认#号
# 包含注释符的行和空行会被跳过
>>> np.genfromtxt('a.txt', comments = '#')
array([[ 1., 2.],...]])
# 跳过开头的行,0表示不跳过
>>> np.genfromtxt('a.txt', skip_header = 0)
array([[ 1., 2.],
[ 3., 4....]])
# 选择对应的列,下标从0开始
>>> np.genfromtxt('a.txt', usecols = (1,))
array([ 2., 4.])...重点来看下其缺失值处理功能,对于文件中无法转换为同一类型的内容,自动用np.nan来表示,同时也可以自定义缺失值,并指定缺失值的填充方式,示意如下
# 自动转换为nan
>>> np.genfromtxt...]])
# 指定缺失值对应的字符
>>> np.genfromtxt('a.txt', missing_values = 'NA')
array([[ 1., 2.],
[ nan, 4