- Hands-On Artificial Intelligence for IoT
- Amita Kapoor
- 134字
- 2021-07-02 14:02:01
Using HDF5 with pandas
We can also read and write HDF5 files with pandas. To read HDF5 files with pandas, they must first be created with it. For example, let's use pandas to create a HDF5 file containing global power values:
import pandas as pd
import numpy as np
arr = np.loadtxt('temp.csv', skiprows=1, usecols=(2,3), delimiter=',')
import pandas as pd
store=pd.HDFStore('hdfstore_demo.hdf5')
print(store)
store['global_power']=pd.DataFrame(arr)
store.close()
Now let's read the HDF5 file that we created and print the array back:
import pandas as pd
store=pd.HDFStore('hdfstore_demo.hdf5')
print(store)
print(store['global_power'])
store.close()
The values of the DataFrame can be read in three different ways:
- store['global_power']
- store.get('global_power')
- store.global_power
pandas also provides the high-level read_hdf() function and the to_hdf() DataFrame method for reading and writing HDF5 files.
More documentation on HDF5 in pandas is available at the following link: http://pandas.pydata.org/pandas-docs/stable/io.html#io-hdf5.
推薦閱讀
- Mastering Spark for Data Science
- Hands-On Artificial Intelligence on Amazon Web Services
- AWS:Security Best Practices on AWS
- Visual FoxPro 6.0數據庫與程序設計
- 精通Excel VBA
- 機器自動化控制器原理與應用
- Python Data Science Essentials
- 塊數據5.0:數據社會學的理論與方法
- 完全掌握AutoCAD 2008中文版:機械篇
- Implementing Splunk 7(Third Edition)
- 工業機器人安裝與調試
- Mastering Exploratory Analysis with pandas
- Puppet 3 Beginner’s Guide
- 機器人剛柔耦合動力學
- 基于元胞自動機的人群疏散系統建模與分析