pandas.read_hdf¶
-
pandas.
read_hdf
(path_or_buf, key=None, mode: str = 'r', errors: str = 'strict', where=None, start: Union[int, NoneType] = None, stop: Union[int, NoneType] = None, columns=None, iterator=False, chunksize: Union[int, NoneType] = None, **kwargs)[source]¶ Read from the store, close it if we opened it.
Retrieve pandas object stored in file, optionally based on where criteria
- Parameters
- path_or_bufstr, path object, pandas.HDFStore or file-like object
Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, ftp, s3, and file. For file URLs, a host is expected. A local file could be:
file://localhost/path/to/table.h5
.If you want to pass in a path object, pandas accepts any
os.PathLike
.Alternatively, pandas accepts an open
pandas.HDFStore
object.By file-like object, we refer to objects with a
read()
method, such as a file handler (e.g. via builtinopen
function) orStringIO
.New in version 0.21.0: support for __fspath__ protocol.
- keyobject, optional
The group identifier in the store. Can be omitted if the HDF file contains a single pandas object.
- mode{‘r’, ‘r+’, ‘a’}, default ‘r’
Mode to use when opening the file. Ignored if path_or_buf is a
pandas.HDFStore
. Default is ‘r’.- wherelist, optional
A list of Term (or convertible) objects.
- startint, optional
Row number to start selection.
- stopint, optional
Row number to stop selection.
- columnslist, optional
A list of columns names to return.
- iteratorbool, optional
Return an iterator object.
- chunksizeint, optional
Number of rows to include in an iteration when using an iterator.
- errorsstr, default ‘strict’
Specifies how encoding and decoding errors are to be handled. See the errors argument for
open()
for a full list of options.- **kwargs
Additional keyword arguments passed to HDFStore.
- Returns
- itemobject
The selected object. Return type depends on the object stored.
See also
DataFrame.to_hdf
Write a HDF file from a DataFrame.
HDFStore
Low-level access to HDF files.
Examples
>>> df = pd.DataFrame([[1, 1.0, 'a']], columns=['x', 'y', 'z']) >>> df.to_hdf('./store.h5', 'data') >>> reread = pd.read_hdf('./store.h5')