一、测试文本数据
https://download.csdn.net/download/hyj_king/83921256
二、技术点
# fname: 文件的名称, 可以是文件名, 也可以是ugz或者bz2的压缩文件;
# dtype: 数据类型, 可选, 默认是float;
# delimiter: 分隔符字符串, 默认情况是任何的空格,
# skiprows: 跳过前xx行, 一般情况跳过第一行;
# usecols: 读取指定的列, 可以是元组;
# unpack: 如果为True, 对返回的数组对象转置;
# loadtxt源代码
# def loadtxt(fname, dtype=float, comments='#', delimiter=None,
# converters=None, skiprows=0, usecols=None, unpack=False,
# ndmin=0, encoding='bytes', max_rows=None):
三、代码
import numpy as np
if __name__ == "__main__":
data1 = np.loadtxt("movie.txt", dtype="U", skiprows=0, delimiter=",")
print(data1)
data2 = np.loadtxt("movie.txt", dtype="U", usecols=(0, 2), skiprows=1, delimiter=",")
print(data2)
[['上映日期' '电影票房' '观看人数']
['20210912' '8990' '7001']
['20210913' '7893' '6098']
['20210914' '5678' '190']
['20210915' '67892' '1235']
['20210916' '6892' '765']]
[['20210912' '7001']
['20210913' '6098']
['20210914' '190']
['20210915' '1235']
['20210916' '765']]
|