Я объединяю данные в FinalData переменную. Теперь я хочу вставить эти данные в sql таблицу.
import pandas as pd
import pandas.io.sql
import pyodbc
server = 'Lppp-5CD812F42\SQLEXPRESS'
db = 'HDb'
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + server + ';DATABASE=' + db +
';Trusted_Connection=yes')
cursor = conn.cursor()
data = pd.read_excel('C:\\Users\\neeraj.ya\\Xerox\\Python\\Address.xlsx')
data1 = pd.read_excel('C:\\Users\\neeraj.ya\\Xerox\\Python\\BAddress.xlsx')
## Joining on data1 and data ##
FinalData =data.join(data1, on='AddressID', how='inner', lsuffix='_left', rsuffix='_right')
print(FinalData)
query1 = """
CREATE TABLE [dbo].[pythtbl1] (
AddressID varchar(255),
PostalCode varchar(255),
AddressTypeID varchar(255)
)"""
query = """INSERT INTO [dbo].[pythtbl1] (AddressID, PostalCode, AddressTypeID) VALUES (?,?,?)"""
try:
cursor.execute(query1)
conn.commit()
except pyodbc.ProgrammingError:
pass