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

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.

主站蜘蛛池模板: 电白县| 乌审旗| 博兴县| 武安市| 武城县| 晋州市| 惠来县| 正阳县| 泽州县| 天门市| 二手房| 广丰县| 台东市| 老河口市| 西贡区| 招远市| 西宁市| 阳西县| 理塘县| 济阳县| 手游| 华容县| 新平| 竹山县| 错那县| 任丘市| 通辽市| 牡丹江市| 望江县| 宣恩县| 磐安县| 德州市| 南投市| 滦南县| 张家口市| 沂水县| 松原市| 平邑县| 西峡县| 淮北市| 南和县|