惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
V
Visual Studio Blog
小众软件
小众软件
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
T
Tor Project blog
Jina AI
Jina AI
GbyAI
GbyAI
C
Comments on: Blog
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
A
Arctic Wolf
有赞技术团队
有赞技术团队
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
Webroot Blog
Webroot Blog
C
Cisco Blogs
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
H
Hacker News: Front Page
D
Darknet – Hacking Tools, Hacker News & Cyber Security
D
Docker
P
Palo Alto Networks Blog
The Register - Security
The Register - Security
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志

博客园 - 隐客

商品期权的保证金计算 写个chrome插件屏蔽某些视频,防止孩子看些不正常的视频 获取个股信息的东财数据 AI量化qlib学习笔记四:测试模型 AI量化qlib学习笔记三:训练模型 AI量化qlib学习笔记二:转换数据 AI量化qlib学习笔记 一:清洗数据 python 打包工具 python: 与通达信联动 随手写了街机一键发招的代码 使用pybind11封装c++的dll,供python调用 用py-spy对python线程查看cpu等资源 占用和消耗 通过selenium获取性能日志中的response的body Windows Server 2012无法安装 .NET3.5-安装角色或功能失败,找不到源文件 vscode 扩展商店打不开的解决办法 通过1分钟生成其它线的bar配置文件 微信pc防撤回修改笔记 关于在python中时间的转换 把本地vscode项目代码传到gitee上
用numpy读取结构化二进制文件
隐客 · 2023-05-16 · via 博客园 - 隐客

之前做了一个读取TDX数据的代码,如下:

def stock_lc5(self,filepath, name ):
        file_path=filepath+"\\" + name
        file_size = os.path.getsize(file_path)
        pos=0

        if(file_size>16000):
            pos=file_size-16000
        with open(file_path, 'rb') as f:   
            f.seek(pos, os.SEEK_SET)

              loc=0
              while True:
                  # print ("loc",loc)
                  li2 = f.read(32)  # 读取一个5分钟数据
                  if not li2:  # 如果没有数据了,就退出
                      break
                  data2 = struct.unpack('HHffffllf', li2)  # 解析数据
                  date_str  = self.get_date_str(data2[0], data2[1])  # 解析日期和分时                
                  data2_list = list(data2)  # 将数据转成list
                  data2_list[1] = date_d  # 将list二个元素更改为日期 时:分
                  del (data2_list[0])  # 删除list第一个元素
                  data2_list.append(date_str)
 
   
                 df.loc[loc]=data2_list
                 loc+=1
               print(df)
            df.to_csv(file_path+".csv")
            print(name," convert is done\n")

我去,那个速度,酸爽,想想还是用结构化的来读比较快

    def stock_lc5(self,filepath, name):
        file_path=filepath+"\\" + name
        file_size = os.path.getsize(file_path)
        pos=0
        dtype = np.dtype([
            ("date_int", np.uint16),
            ("time_int", np.uint16),
            ("open", np.float32),
            ("high", np.float32),
            ("low", np.float32),
            ("close", np.float32),
            ("amount", np.int32),
            ("volume", np.int32),
            ("other", np.float32),
        ])
        if(file_size>16000):
            pos=file_size-16000
        with open(file_path, 'rb') as f:   
            f.seek(pos, os.SEEK_SET)
            data = np.fromfile(f, dtype=dtype)
            df=pd.DataFrame(data,columns=["date_int","time_int","open","high","low","close","amount","volume","other"])
             
            df['eob']= df.apply(lambda row:self.get_date_str(row["date_int"],row ["time_int"]), axis=1)
 
            df.to_csv(file_path+".csv")
            print(name," convert is done\n")

这速度,真的爽爆了