Create and Read Pickle Files in Python

visibility 3,394 access_time 2 years ago languageEnglish

Pickle files are commonly used Python data related projects. This article shows how to create and load pickle files using Pandas. 

Create pickle file

import pandas as pd 
import numpy as np

file_name="data/test.pkl"
data = np.random.randn(1000, 2)
# pd.set_option('display.max_rows', None)
df = pd.DataFrame(data=data, columns=['foo', 'bar'])
print(df)
df.to_pickle(file_name)

Read pickle file

import pandas as pd 
import numpy as np

file_name="data/test.pkl"
df2 = pd.read_pickle(file_name)
print(df2)
info Last modified by Administrator 2 years ago copyright This page is subject to Site terms.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

timeline Stats
Page index 3.88
More from Kontext
Call SQL Server Stored Procedure in Python
visibility 648
thumb_up 0
access_time 5 months ago
Call SQL Server Stored Procedure in Python
Pandas Save DataFrame to SQLite
visibility 2,899
thumb_up 1
access_time 2 years ago
Kafka Topic Partitions Walkthrough via Python
visibility 6,007
thumb_up 4
access_time 2 years ago
Kafka Topic Partitions Walkthrough via Python