मान लीजिए आपके पास एक डेटाफ्रेम है और पिकल फाइल में एक्सपोर्ट करने और फाइल से कंटेंट पढ़ने का परिणाम है,
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