- 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.
推薦閱讀
- Visual FoxPro 6.0數(shù)據(jù)庫(kù)與程序設(shè)計(jì)
- Apache Hive Essentials
- MCSA Windows Server 2016 Certification Guide:Exam 70-741
- 精通數(shù)據(jù)科學(xué)算法
- 電腦主板現(xiàn)場(chǎng)維修實(shí)錄
- 突破,Objective-C開(kāi)發(fā)速學(xué)手冊(cè)
- 悟透AutoCAD 2009案例自學(xué)手冊(cè)
- Visual FoxPro程序設(shè)計(jì)
- Salesforce Advanced Administrator Certification Guide
- 從零開(kāi)始學(xué)SQL Server
- 空間機(jī)器人
- 人工智能:智能人機(jī)交互
- Hands-On Business Intelligence with Qlik Sense
- 數(shù)據(jù)庫(kù)基礎(chǔ):Access
- SolarWinds Server & Application Monitor:Deployment and Administration