BetterDocs
Home
Docs

Creation | pd.read_pickle()

Method:

pd.read_pickle(filepath_or_buffer, compression='infer', storage_options=None)

Reads a pickled object stored in a file and returns a DataFrame.

Returns:

pandas.core.frame.DataFrame

Parameters:

filepath_or_buffer: (file_path or buffer), Optional-

Path to the pickle file or file-like object to be read.

import pandas as pd

# Writing and reading a DataFrame with pickle
data = {'Name': ['Better', 'Docs'], 'Age': [25, 30]}
df = pd.DataFrame(data)
df.to_pickle('data.pkl')  # Save to pickle

# Read back from pickle
df_loaded = pd.read_pickle(filepath_or_buffer='data.pkl')
print(df_loaded)
'''
Output:
     Name  Age
0  Better   25
1    Docs   30
'''

.to_pickle  is used to pickle(serialize) object to file.

compression: str, Optional-

Specifies compression type (e.g., 'gzip', 'bz2'); detects from file extension if 'infer'.

storage_options: dict, Optional-

Dictionary of storage-specific options, such as credentials for cloud storage.


Logo

BetterDocs

Support

EmailDiscordForms

Documentations

Python

Company

AboutDocs

Policies

Terms of ServicePrivacy Policy