In the data preparation step, we will use various data structures such as dictionaries, lists, arrays, or DataFrames. Sometimes, we might want to save them for future reference or send them to someone else. Here, a pickle object comes into the picture. pickle serializes the objects to save them and can be loaded again any time. pandas offer two functions: read_pickle() for loading pandas objects and to_pickle() for saving Python objects:
# import pandas
import pandas as pd
# Read CSV file
df=pd.read_csv('demo.csv', sep=',' , header=None)
# Save DataFrame object in pickle file
df.to_pickle('demo_obj.pkl')
In the preceding code, we read the demo.csv file using the read_csv() method with sep and header parameters. Here, we have assigned sep with a comma and header with None. Finally, we have written the dataset to a pickle object using the to_pickle() method. Let's see how to read pickle objects using the...