pandas.read_pickle#
- pandas.read_pickle(filepath_or_buffer, compression='infer', storage_options=None)[源代码]#
从文件中加载腌制Pandas对象(或任何对象)。
警告
加载从不可信来源接收的已腌渍数据可能是不安全的。看见 here 。
- 参数
- filepath_or_buffer字符串、路径对象或类似文件的对象
字符串、路径对象(实现
os.PathLike[str]
)或实现二进制文件的类似文件的对象readlines()
功能。在 1.0.0 版更改: 接受URL。URL不限于S3和GCS。
- compression字符串或词典,默认为‘INFER’
For on-the-fly decompression of on-disk data. If 'infer' and 'filepath_or_buffer' is path-like, then detect compression from the following extensions: '.gz', '.bz2', '.zip', '.xz', or '.zst' (otherwise no compression). If using 'zip', the ZIP file must contain only one data file to be read in. Set to
None
for no decompression. Can also be a dict with key'method'
set to one of {'zip'
,'gzip'
,'bz2'
,'zstd'
} and other key-value pairs are forwarded tozipfile.ZipFile
,gzip.GzipFile
,bz2.BZ2File
, orzstandard.ZstdDecompressor
, respectively. As an example, the following could be passed for Zstandard decompression using a custom compression dictionary:compression={'method': 'zstd', 'dict_data': my_compression_dict}
.在 1.4.0 版更改: Z标准支持。
- storage_optionsDICT,可选
对特定存储连接有意义的额外选项,例如主机、端口、用户名、密码等。对于HTTP(S)URL,键-值对被转发到
urllib.request.Request
作为标题选项。对于其他URL(例如,以“s3://”和“gcs://”开头),键-值对被转发到fsspec.open
。请看fsspec
和urllib
有关更多详细信息和有关存储选项的更多示例,请参阅 here 。1.2.0 新版功能.
- 退货
- unpickled与文件中存储的对象类型相同
参见
DataFrame.to_pickle
将DataFrame对象保留(序列化)到文件。
Series.to_pickle
Pickle(序列化)系列对象到文件。
read_hdf
将HDF5文件读入DataFrame。
read_sql
将SQL查询或数据库表读入DataFrame。
read_parquet
加载拼图对象,返回DataFrame。
注意事项
Read_Pickle只保证向后兼容Pandas0.20.3。
示例
>>> original_df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)}) >>> original_df foo bar 0 0 5 1 1 6 2 2 7 3 3 8 4 4 9 >>> pd.to_pickle(original_df, "./dummy.pkl")
>>> unpickled_df = pd.read_pickle("./dummy.pkl") >>> unpickled_df foo bar 0 0 5 1 1 6 2 2 7 3 3 8 4 4 9