import pickle
import mysql.connector
import pandas as pd
my_connect = mysql.connector.connect(
host="localhost",
user="userid",
passwd="****",
database="my_tutorial"
)
####### end of connection ####
my_data = pd.read_sql("SELECT * FROM student LIMIT 0,5",my_connect)
print(my_data) # print output to check
###### end of collecting data and creation of DataFrame #######
fob = open('my_student','wb') # file handling object is created
pickle.dump(my_data,fob) # generated the Pickle
fob.close()
Creating DataFrame by using data from MySQL table
fob=open('my_student','rb')
my_dict1=pickle.load(fob) # reading the Pickle
fob.close()
print(my_dict1)
Output is here
id name class mark sex
0 1 John Deo Four 75 female
1 2 Max Ruin Three 85 male
2 3 Arnold Three 55 male
3 4 Krish Star Four 60 female
4 5 John Mike Four 60 female
my_data.to_pickle("my_student")
import pandas as pd
my_dict2=pd.read_pickle('my_student')
print(my_dict2)
Output is here
id name class mark sex
0 1 John Deo Four 75 female
1 2 Max Ruin Three 85 male
2 3 Arnold Three 55 male
3 4 Krish Star Four 60 female
4 5 John Mike Four 60 female
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.