【发布时间】:2021-03-12 10:14:46
【问题描述】:
我正在尝试将 Pandas 中的 SQL 服务器数据作为数据框导入。我目前有以下代码:
import pandas as pd
import pyodbc
# SQL Authentication
conn = pyodbc.connect(
'Driver={SQL Server};'
'Server=Servername;'
'Database=DBName;'
'UID=logIn;'
'PWD=Password;')
cursor = conn.cursor()
cursor.execute('SELECT * FROM Table')
result = cursor.fetchall()
cursor.close()
print(result)
这会返回数据,但格式如下:
[(24609189, 'EURTRY.pro', Decimal('5'), Decimal('11'), Decimal('5.0000'), Decimal('105.0000'), Decimal('-2.200000'), Decimal('0.000000'), datetime.datetime(2018, 10, 15, 16, 47, 17, 800000), None)]
我怎样才能将它放入数据框中,有没有办法删除数字前面的Decimal?
【问题讨论】:
-
你尝试过原生pandas方法
pd.read_sql("SELECT * FROM schema.Table", conn)
标签: python sql sql-server pandas