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

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.

主站蜘蛛池模板: 贵港市| 汉川市| 民县| 将乐县| 锦屏县| 天水市| 乐东| 高台县| 比如县| 邯郸县| 汉中市| 米易县| 上蔡县| 普格县| 平阴县| 吴江市| 嫩江县| 黄骅市| 比如县| 阳新县| 镇平县| 宜宾市| 松原市| 德格县| 晋中市| 湛江市| 车致| 怀集县| 正定县| 泸州市| 德江县| 容城县| 五河县| 邹城市| 荥经县| 军事| 赤峰市| 伊春市| 常山县| 永顺县| 黄冈市|