- 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.
推薦閱讀
- Google Cloud Platform Cookbook
- Deep Learning Quick Reference
- OpenStack Cloud Computing Cookbook(Second Edition)
- MATLAB/Simulink權威指南:開發環境、程序設計、系統仿真與案例實戰
- Mastering Game Development with Unreal Engine 4(Second Edition)
- 激光選區熔化3D打印技術
- 人工智能:語言智能處理
- Salesforce Advanced Administrator Certification Guide
- MPC5554/5553微處理器揭秘
- 智能制造系統及關鍵使能技術
- 手把手教你學Flash CS3
- Unreal Development Kit Game Design Cookbook
- Machine Learning with Spark(Second Edition)
- Learn Microsoft Azure
- 穿越計算機的迷霧