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

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.

主站蜘蛛池模板: 邯郸市| 苗栗县| 斗六市| 海阳市| 将乐县| 会同县| 安阳市| 孟津县| 灯塔市| 江山市| 鄂尔多斯市| 抚宁县| 宾川县| 兴山县| 汝州市| 深泽县| 贡觉县| 蒙阴县| 乌拉特中旗| 龙泉市| 阿合奇县| 民勤县| 临沂市| 蒙自县| 酉阳| 东乌珠穆沁旗| 五大连池市| 阜康市| 汶上县| 比如县| 承德县| 无为县| 襄城县| 增城市| 浙江省| 双牌县| 民权县| 海口市| 兴安县| 白水县| 汉阴县|