Q. Write a program to get following data in two dataframes :
Df1
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.
Answer :-
import pandas as pd import pymysql from sqlalchemy import create_engine engine=create_engine('mysql+pymysql://root:0000000000@localhost/pathwalla') con=engine.connect() d1={'Roll no':[1,2,3],'Name':['path','walla','incredible']} d2={'Roll no':[1,2,3],'Mark1':[12,15,18],'Mark2':[12,105,158],'Mark3':[12,105,158]} df=pd.DataFrame(d1) df1=pd.DataFrame(d2) df1.to_sql('new',con) df.to_sql('new table ',con)
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )