jeudi 12 février 2015

reading pandas frame from sqlite3 using variable in where clause

I have a fairly large sqlite3 database and sometimes I get a memory error when trying to read it into a Pandas dataframe. I can use the WHERE function to limit the size of the frame so that it will work.



con = sqlite3.connect("myDB.db")
frame = pd_sql.read_frame('SELECT * FROM Basketball WHERE League == "NBA"', pinnyCon)


How would I name a variable so that something like this would work?



def GetLeagueFrame(leagueName):
con = sqlite3.connect("myDB.db")
frame = pd_sql.read_frame('SELECT * FROM Basketball WHERE League == leagueName', pinnyCon)
con.close()
return frame

Aucun commentaire:

Enregistrer un commentaire