How to save a Pandas Dataframe to a pickle file?

0 votes

Hi Guys,

I am new to the Pandas module. I want to save the Dataframe in a pickle file. How can I do that?

Oct 17 in Python by akhtar
• 32,960 points
106 views

1 answer to this question.

0 votes

Hi@akhtar,

Python pickle module is used for serializing and de-serializing a Python object structure. Any object in Python can be pickled so that it can be saved on disk. You can use the below commands to save the Dataframe in a pickle file.

import pandas as pd
df = pd.DataFrame({"foo": range(5), "bar": range(5, 10)})
pd.to_pickle(df, "./dummy.pkl")
answered Oct 17 by MD
• 77,580 points

Related Questions In Python

0 votes
1 answer

How to convert a Pandas GroupBy object to DataFrame in Python

g1 here is a DataFrame. It has a hierarchical index, ...READ MORE

answered Nov 12, 2018 in Python by Nymeria
• 3,520 points
23,313 views
0 votes
1 answer

How to find if a value exists in Pandas dataframe?

Try this:​ for name in df['Name']: ...READ MORE

answered Apr 8, 2019 in Python by Tina
8,703 views
0 votes
1 answer

How to append a row to a Pandas dataframe?

You can use the append method provided by pandas ...READ MORE

answered May 9, 2019 in Python by Raj
1,090 views
0 votes
1 answer

How to print the index of a Pandas Dataframe?

You can do this using the code ...READ MORE

answered May 12, 2019 in Python by Usha
4,805 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,557 views
0 votes
0 answers
0 votes
1 answer

How to save one list in a text file in Python?

Hi@akhtar, There is no inbuilt function available to ...READ MORE

answered Jun 25 in Python by MD
• 77,580 points
101 views
0 votes
1 answer

How to write a HDF file from a DataFrame?

Hi@akhtar, Hierarchical Data Format (HDF) is a set ...READ MORE

answered Oct 17 in Python by MD
• 77,580 points
21 views