KnowledgeBoat Logo
|

Informatics Practices

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.

Python Pandas

4 Likes

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()
    first_25_rows = sdf.head(25)
    first_25_rows.to_sql('Records', mycon, if_exists = 'replace', index = False)

Answered By

4 Likes


Related Questions