Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.to_hdf#

DataFrame.to_hdf(path_or_buf,*,key,mode='a',complevel=None,complib=None,append=False,format=None,index=True,min_itemsize=None,nan_rep=None,dropna=None,data_columns=None,errors='strict',encoding='UTF-8')[source]#

Write the contained data to an HDF5 file using HDFStore.

Hierarchical Data Format (HDF) is self-describing, allowing anapplication to interpret the structure and contents of a file withno outside information. One HDF file can hold a mix of related objectswhich can be accessed as a group or as individual objects.

In order to add another DataFrame or Series to an existing HDF fileplease use append mode and a different a key.

Warning

One can store a subclass ofDataFrame orSeries to HDF5,but the type of the subclass is lost upon storing.

For more information see theuser guide.

Parameters:
path_or_bufstr or pandas.HDFStore

File path or HDFStore object.

keystr

Identifier for the group in the store.

mode{‘a’, ‘w’, ‘r+’}, default ‘a’

Mode to open file:

  • ‘w’: write, a new file is created (an existing file withthe same name would be deleted).

  • ‘a’: append, an existing file is opened for reading andwriting, and if the file does not exist it is created.

  • ‘r+’: similar to ‘a’, but the file must already exist.

complevel{0-9}, default None

Specifies a compression level for data.A value of 0 or None disables compression.

complib{‘zlib’, ‘lzo’, ‘bzip2’, ‘blosc’}, default ‘zlib’

Specifies the compression library to be used.These additional compressors for Blosc are supported(default if no compressor specified: ‘blosc:blosclz’):{‘blosc:blosclz’, ‘blosc:lz4’, ‘blosc:lz4hc’, ‘blosc:snappy’,‘blosc:zlib’, ‘blosc:zstd’}.Specifying a compression library which is not available issuesa ValueError.

appendbool, default False

For Table formats, append the input data to the existing.

format{‘fixed’, ‘table’, None}, default ‘fixed’

Possible values:

  • ‘fixed’: Fixed format. Fast writing/reading. Not-appendable,nor searchable.

  • ‘table’: Table format. Write as a PyTables Table structurewhich may perform worse but allow more flexible operationslike searching / selecting subsets of the data.

  • If None, pd.get_option(‘io.hdf.default_format’) is checked,followed by fallback to “fixed”.

indexbool, default True

Write DataFrame index as a column.

min_itemsizedict or int, optional

Map column names to minimum string sizes for columns.

nan_repAny, optional

How to represent null values as str.Not allowed with append=True.

dropnabool, default False, optional

Remove missing values.

data_columnslist of columns or True, optional

List of columns to create as indexed data columns for on-diskqueries, or True to use all columns. By default only the axesof the object are indexed. SeeQuery via data columns. formore information.Applicable only to format=’table’.

errorsstr, default ‘strict’

Specifies how encoding and decoding errors are to be handled.See the errors argument foropen() for a full listof options.

encodingstr, default “UTF-8”

See also

read_hdf

Read from HDF file.

DataFrame.to_orc

Write a DataFrame to the binary orc format.

DataFrame.to_parquet

Write a DataFrame to the binary parquet format.

DataFrame.to_sql

Write to a SQL table.

DataFrame.to_feather

Write out feather-format for DataFrames.

DataFrame.to_csv

Write out to a csv file.

Examples

>>>df=pd.DataFrame({'A':[1,2,3],'B':[4,5,6]},...index=['a','b','c'])>>>df.to_hdf('data.h5',key='df',mode='w')

We can add another object to the same file:

>>>s=pd.Series([1,2,3,4])>>>s.to_hdf('data.h5',key='s')

Reading from HDF file:

>>>pd.read_hdf('data.h5','df')A  Ba  1  4b  2  5c  3  6>>>pd.read_hdf('data.h5','s')0    11    22    33    4dtype: int64

[8]ページ先頭

©2009-2025 Movatter.jp