Pandas从MSSQL加载数据帧

时间:2018-05-01 11:46:33

标签: sql-server python-3.x pandas record-linkage

我正在尝试将数据加载到数据框中,以便稍后在recordlinkage中使用它,但是我收到了错误:

清空DataFrame 列:[FirstName,LastName,CompanyName] 指数:[]

我不确定我做错了吗?

代码:

import pymssql
import time

import recordlinkage
import pandas.io.sql as psql



#SQL connection
conn = pymssql.connect(host='server', user='xx', password='xx', database='Test')
cursor = conn.cursor()


print(time.ctime())


sql = "select FirstName, LastName, CompanyName, ID from [Test].[dbo].[Person]with(nolock) where ID < 100"





dfA = psql.read_sql(sql, conn,  index_col='ID')
print(dfA)

# Indexation step

pcl = recordlinkage.index.Block(on='FirstName')
pairs = pcl.index(dfA)

# Comparison step
compare_cl = recordlinkage.Compare()

compare_cl.exact('FirstName', 'FirstName', label='FirstName')
compare_cl.string('LastName', 'LastName', method='jarowinkler', threshold=0.85, label='LastName')
compare_cl.string('CompanyName', 'CompanyName', threshold=0.85, label='CompanyName')

features = compare_cl.compute(pairs, dfA)

# Classification step
matches = features[features.sum(axis=1) > 3]

print(len(matches))

print(matches)

1 个答案:

答案 0 :(得分:0)

此部分返回错误,表明DataFrame中没有数据 修复此更改&gt; 3至> 2或&gt; 1

matches = features[features.sum(axis=1) > 3]