#! /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2018/9/12 17:12
# @File : MssqlCase
# @Software: PyCharm
import pymssql
SERVER = 'localhost'
USER = 'sa'
PASSWD = '***'
conn = pymssql.connect(SERVER,USER,PASSWD,"默认DB")
cursor = conn.cursor()
sql_1 = """
select top 10 * from Tmp_ma_total
"""
cursor.execute(sql_1)
row = cursor.fetchall()
#用来存放表头
al = []
index = cursor.description
#取出表头
for i in range(len(index)):
al.append(index[i][0])
#关闭连接
cursor.close()
conn.close()
#导入到Pandas
import pandas as pd
df = pd.DataFrame(row,columns=al)
print(df)
网友评论