Python笔记:3.1.4文件读写

    xiaoxiao2022-07-02  110

    # -*- coding: utf-8 -*- """ Created on Wed May 22 10:42:38 2019 @author: User """ import numpy as np stock=np.dtype([('id',np.str,5), ('time',np.str,10), ('code',np.str,10), ('open_p',np.float64), ('close_p',np.float64), ('low_p',np.float64), ('vol',np.int32), ('high_p',np.float64), ('col',np.int32)]) jd_stock=np.loadtxt('d:\stock.csv', delimiter=',',dtype=stock) print(jd_stock)

    加载将近4000条记录速度非常快。测试用的stock.csv在我的下载中。

    运行:

    [('1', '20130902', '600028', 4.41, 4.43, 4.37, 17275, 4.41, 392662)  ('2', '20130903', '600028', 4.41, 4.46, 4.4 , 19241, 4.45, 434177)  ('3', '20130904', '600028', 4.44, 4.49, 4.42, 20106, 4.47, 451470) ...  ('3980', '20190327', '600019', 7.14, 7.15, 7.08, 29373, 7.13, 412887)  ('3981', '20190328', '600019', 7.1 , 7.12, 7.05, 25452, 7.08, 359576)  ('3982', '20190329', '600019', 7.07, 7.25, 7.07, 54683, 7.23, 762021)]

    最新回复(0)