- Hands-On Artificial Intelligence for IoT
- Amita Kapoor
- 121字
- 2021-07-02 14:02:01
Using HDF5 with PyTables
Let's first create an HDF5 file from the numeric data we have in the temp.csv file with the following steps:
- Get the numeric data:
import numpy as np
arr = np.loadtxt('temp.csv', skiprows=1, usecols=(2,3), delimiter=',')
- Open the HDF5 file:
import tables
h5filename = 'pytable_demo.hdf5'
with tables.open_file(h5filename,mode='w') as h5file:
- Get the root node:
root = h5file.root
- Create a group with create_group() or a dataset with create_array(), and repeat this until all the data is stored:
h5file.create_array(root,'global_power',arr)
- Close the file:
h5file.close()
Let's read the file and print the dataset to make sure it is properly written:
with tables.open_file(h5filename,mode='r') as h5file:
root = h5file.root
for node in h5file.root:
ds = node.read()
print(type(ds),ds.shape)
print(ds)
We get the NumPy array back.
推薦閱讀
- Microsoft Dynamics CRM Customization Essentials
- Ansible Configuration Management
- Mastercam 2017數控加工自動編程經典實例(第4版)
- 條碼技術及應用
- PIC單片機C語言非常入門與視頻演練
- 深度學習中的圖像分類與對抗技術
- Multimedia Programming with Pure Data
- Windows內核原理與實現
- Photoshop CS3圖層、通道、蒙版深度剖析寶典
- Kubernetes for Serverless Applications
- Red Hat Linux 9實務自學手冊
- 筆記本電腦維修90個精選實例
- Dreamweaver CS6精彩網頁制作與網站建設
- IBM? SmartCloud? Essentials
- Microsoft Dynamics CRM 2013 Marketing Automation