Informatics Practices
The DataFrame SDF stores the sales records of 100 salesmen. Write a program to store this as a table in database namely "company" on MySQL.
Python Pandas
1 Like
Answer
import pandas as pd
from sqlalchemy import create_engine
import pymysql
def sales(sdf):
engine = create_engine('mysql+pymysql://root:Mypass@localhost/company')
mycon = engine.connect()
sdf.to_sql('Records', mycon, if_exists = 'replace', index = False)Answered By
1 Like
Related Questions
Write a program to get following data in two DataFrames :
df 1:
Roll no Name 1 ABC 2 DEF df2:
Roll no Marks 1 Marks 2 Marks 3 1 70 80 75 2 60 65 70 Store these DataFrames as two separate tables in the same database.
You have a database on MySQL namely school having three tables in it — Student, Subject, Teacher. Write a program to store these tables in three DataFrames.
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.
The sales table of company database of MySQL stores the sales records of 100 salesmen. Write a program to load only those records in DataFrame which have made sales more than of 50000/-.