mardi 3 novembre 2015

Python "InterfaceError: Error binding parameter 2 - probably unsupported type."

When I run the following code, I keep getting the "InterfaceError: Error binding parameter 2 - probably unsupported type" error, and I need help identifying where the problem is. Everything works fine up until I try to send the data to sql through.

anagramsdf.to_sql('anagrams',con=conn,if_exists='replace',index=False)
cdf=pd.read_sql("select (distinct ID) from anagrams;",conn)

Any help would be appreciated, thank you!

#import libraries 
import urllib, itertools

#import dictionary
scrabble = urllib.urlopen('http://ift.tt/1P8fvkR').read().split()
#print the length of the dictionary
print len(scrabble)

#make anagrams from scrabble list
anagrams = [tuple(g) for k,g in itertools.groupby(sorted(scrabble, key=sorted), key=sorted)]


#print unique anagrams

print "The number of unique anagrams is: " ,len(set(anagrams))

#print the largest anagram  
print "Largest number of anagrams for a word is: ", len(max(anagrams, key=len)) 
print "Largest anagram word and values is: ", max(anagrams, key=len)

import pandas as pd
import sqlite3



conn = sqlite3.connect("anagrams_scrabble")
xsorted=sorted(anagrams,key=sorted)
xunique=[x[0] for x in anagrams]
print len(xunique)

xunique=pd.Series(xunique)
xanagrams=pd.Series(anagrams)
anagramsdf=pd.concat([xunique,dfcount,xanagrams],axis=1)
anagramsdf.columns=['ID','anagram_count','anagram_list']

print anagramsdf


c=conn.cursor()
c.execute("create table anagrams(ID, anagram_count, anagram_list)")
conn.commit()


anagramsdf.to_sql('anagrams',con=conn,if_exists='replace',index=False)
cdf=pd.read_sql("select (distinct ID) from anagrams;",conn)


cdf=pd.read_sql("select max(anagram_count) from anagrams;",conn)
cdf
def print_full(x):
    pd.set_option('display.max_rows', len(x))
    print(x)
    pd.reset_option('display.max_rows')

cdf=pd.read_sql("select * from anagrams where anagram_count=12;",conn)
pd.set_option('max_colwidth',200)
print cdf

Aucun commentaire:

Enregistrer un commentaire