pandas读取MySql/SqlServer数据
读取MySql数据
1 import MySQLdb
2 import pandas as pd
4 conn = MySQLdb.connect(host = host,port = port,user = username,passwd = password,db = db_name)
5 df = pd.read_sql('select * from table_name',con=conn)
6 conn.close()
读取SqlServer数据
1 import pymssql
2
3 conn = pymssql.connect(host=host, port=port ,user=username, password=password, database=database)
4 df = pd.read_sql("select * from table_name",con=conn)
5 conn.close()