yhat / pandasql

sqldf for pandas
MIT License
1.34k stars 184 forks source link

Error with Pandasql Using Anaconda on OSX #21

Open craigsakuma opened 10 years ago

craigsakuma commented 10 years ago

I apologize in advance if I'm not following GitHub protocol. I'm relatively new to GitHub.

I tried following your example on (http://blog.yhathq.com/posts/pandasql-sql-for-pandas-dataframes.html) and got the error below from iPython Notebook.

I'm using the Anaconda distribution of Python/iPython Notebook on a Mac running OSX. I tried searching Stack Overflow and couldn't find a solution to the problem.

Thank you so much for the help. I'm very keen on using pandasql


SCRIPT FROM EXAMPLE:

import matplotlib.pyplot as plt from pandasql import * import pandas as pd

pysqldf = lambda q: sqldf(q, globals())

q = """ SELECT m.date , m.beef , b.births FROM meat m LEFT JOIN births b ON m.date = b.date WHERE m.date > '1974-12-31'; """

meat = load_meat() births = load_births()

df = pysqldf(q) df.births = df.births.fillna(method='backfill')

fig = plt.figure() ax1 = fig.add_subplot(111) ax1.plot(pd.rolling_mean(df['beef'], 12), color='b') ax1.set_xlabel('months since 1975') ax1.set_ylabel('cattle slaughtered', color='b')

ax2 = ax1.twinx() ax2.plot(pd.rolling_mean(df['births'], 12), color='r') ax2.set_ylabel('babies born', color='r') plt.title("Beef Consumption and the Birth Rate") plt.show()


ERROR MESSAGE:

InterfaceError Traceback (most recent call last)

in () 13 m.date > '1974-12-31'; 14 """ ---> 15 df = pysqldf(q) 16 df.births = df.births.fillna(method='backfill') 17 in (q) ----> 1 pysqldf = lambda q: sqldf(q, globals()) 2 q = """ 3 SELECT 4 m.date 5 , m.beef /usr/local/lib/python2.7/site-packages/pandasql/sqldf.pyc in sqldf(q, env, inmemory) 113 df = env[table] 114 df = _ensure_data_frame(df, table) --> 115 _write_table(table, df, conn) 116 117 try: /usr/local/lib/python2.7/site-packages/pandasql/sqldf.pyc in _write_table(tablename, df, conn) 68 raise Exception(msg) 69 ---> 70 write_frame(df, name=tablename, con=conn, flavor='sqlite') 71 72 /Users/danielsack/anaconda/lib/python2.7/site-packages/pandas/io/sql.pyc in write_frame(frame, name, con, flavor, if_exists, **kwargs) 236 if func is None: 237 raise NotImplementedError --> 238 func(frame, name, safe_names, cur) 239 cur.close() 240 con.commit() /Users/danielsack/anaconda/lib/python2.7/site-packages/pandas/io/sql.pyc in _write_sqlite(frame, table, names, cur) 252 else: 253 data = [tuple(x) for x in frame.values.tolist()] --> 254 cur.executemany(insert_query, data) 255 256 InterfaceError: Error binding parameter 0 - probably unsupported type.
ifmihai commented 10 years ago

I have the same issue.

OSX Mavericks, anaconda, ipython qtconsole (if that matters)

I'm not sure, but it maybe a an issue with sqlite3 actually