官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 涪陵区| 邵东县| 双鸭山市| 察雅县| 文安县| 九龙城区| 普格县| 揭阳市| 长兴县| 聂拉木县| 大同市| 佛冈县| 孙吴县| 湄潭县| 庆安县| 县级市| 马公市| 赣州市| 双桥区| 腾冲县| 灵丘县| 太仆寺旗| 北海市| 黎平县| 崇信县| 肇州县| 视频| 手游| 皮山县| 凤冈县| 剑川县| 潢川县| 方山县| 西乌珠穆沁旗| 大关县| 神农架林区| 泸水县| 瓮安县| 太仆寺旗| 凭祥市| 无为县|