我是靠谱客的博主 典雅小刺猬,这篇文章主要介绍python学习记录(1)--python3连接SQl Server,并读取表中数据,现在分享给大家,希望可以做个参考。

1、python3连接SQl Server,并读取表中数据。

import pyodbc
import pandas as pd
# 如需账号、密码登录,则需加入相应参数UID、PWD
cnxn = pyodbc.connect(DRIVER='{SQL Server}',SERVER='.',DATABASE='student_info26')   
sc26 = pd.read_sql("select * from sc26",cnxn)
for i in range(sc26.shape[0]):
    for j in range(sc26.shape[1]):
        try:
            sc26.iloc[i,j] = sc26.iloc[i,j].strip()     # 去掉首尾多余空格
        except:
            pass
        continue
print(sc26)

结果:
表sc26中的数据

最后

以上就是典雅小刺猬最近收集整理的关于python学习记录(1)--python3连接SQl Server,并读取表中数据的全部内容,更多相关python学习记录(1)--python3连接SQl内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(34)

评论列表共有 0 条评论

立即
投稿
返回
顶部