Csv:ID,100、200、300,。。。9900,10000
SQL列:
ID Name
100 Henry
101 John
200 Eric
300 Lucy
import pandas as pd
import pyodbc
import csv
cnxn = pyodbc.connect('DRIVER={SQL Server};''SERVER=my_server;''Trusted_Connection=yes')
cursor = cnxn.cursor()
query = SELECT * FROM Table1
# create csv_dataframe
csv_dateframe = pd.read_csv(r"file_path")
# create sql_dataframe
sql_dateframe = pd.read_sql(query, cnxn)
# innerjoin
pd.merge(csv_dataframe,sql_dataframe,on="ID")