
To read a Pickle file in Pandas we use the read_pickle() function.
Syntax –
pd.read_pickle(path, compression='infer')
Parameters –
- path – path to the pickle file
- compression – 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.
Examples –
Let’s read a pickle file using the read_pickle() function in pandas.
# read a pickle file
df = pd.read_pickle('clothing_store_sales.pkl')
df.head()
