Q. Consider the SDF dataframe storing the sales records of 100 salesmen, write a program that stores only the first 25 rows of the dataframe in a table on MySQL database.
Answer :-
import pandas as pd import pymysql from sqlalchemy import create_engine engine=create_engine('mysql+pymysql://root:0000000000@localhost/company') conn=engine.connect() d1={'sales_record':[1,2,3,4,5,6,7,8,9,10,11, 12, 13, 14, 15, 16, 17, 18, 19, \ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, \ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, \ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, \ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, \ 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, \ 93, 94, 95, 96, 97, 98, 99, 100]} SDF=pd.DataFrame(d1) sdf25only=SDF.head(25) sdf25only.to_sql('sales_record_25',conn)
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )