मान लीजिए आपके पास एक डेटाफ्रेम है और पिकल फ़ाइल में निर्यात करने और फ़ाइल से सामग्री पढ़ने का परिणाम है:
Export to pickle file: Read contents from pickle file: Fruits City 0 Apple Shimla 1 Orange Sydney 2 Mango Lucknow 3 Kiwi Wellington
समाधान
इसे हल करने के लिए, हम नीचे दिए गए चरणों का पालन करेंगे:
एक डेटाफ्रेम परिभाषित करें
डेटाफ्रेम को पिकल फॉर्मेट में निर्यात करें और इसे 'pandas.pickle' नाम दें
df.to_pickle('pandas.pickle')
'pandas.pickle' फ़ाइल से सामग्री पढ़ें और इसे result के रूप में संग्रहीत करें
result = pd.read_pickle('pandas.pickle')
उदाहरण
बेहतर समझ के लिए नीचे दिए गए कार्यान्वयन को देखें:
import pandas as pd
df = pd.DataFrame({'Fruits': ["Apple","Orange","Mango","Kiwi"],
'City': ["Shimla","Sydney","Lucknow","Wellington"]})
print("Export to pickle file:")
df.to_pickle('pandas.pickle')
print("Read contents from pickle file:")
result = pd.read_pickle('pandas.pickle')
print(result)
आउटपुट
Export to pickle file: Read contents from pickle file: Fruits City 0 Apple Shimla 1 Orange Sydney 2 Mango Lucknow 3 Kiwi Wellington