添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hello!! In the Guided Project: Design and Creating a Database, I’ve some problems at point 2. Importing Data into SQLite .

I’m trying to create the game_id column but some times I get a None values and other times I get databse is locked message like this:

OperationalErrorTraceback (most recent call last)
/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
   1408             else:
-> 1409                 cur.execute(*args)
   1410             return cur
OperationalError: database is locked
During handling of the above exception, another exception occurred:
DatabaseErrorTraceback (most recent call last)
<ipython-input-23-8d0bcf3319c8> in <module>()
      9 """
---> 11 run_query(query)
<ipython-input-17-13448779aa06> in run_query(query)
      1 def run_query(query):
      2     conn = sqlite3.connect(db)
----> 3     return pd.read_sql_query(query, conn)
      5 def run_command(query):
/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/io/sql.py in read_sql_query(sql, con, index_col, coerce_float, params, parse_dates, chunksize)
    330     return pandas_sql.read_query(
    331         sql, index_col=index_col, params=params, coerce_float=coerce_float,
--> 332         parse_dates=parse_dates, chunksize=chunksize)
/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/io/sql.py in read_query(self, sql, index_col, coerce_float, params, parse_dates, chunksize)
   1443         args = _convert_params(sql, params)
-> 1444         cursor = self.execute(*args)
   1445         columns = [col_desc[0] for col_desc in cursor.description]
/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
   1419             ex = DatabaseError(
   1420                 "Execution failed on sql '%s': %s" % (args[0], exc))
-> 1421             raise_with_traceback(ex)
   1423     @staticmethod
/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/compat/__init__.py in raise_with_traceback(exc, traceback)
    383         if traceback == Ellipsis:
    384             _, _, traceback = sys.exc_info()
--> 385         raise exc.with_traceback(traceback)
    386 else:
    387     # this version of raise is a syntax error in Python 3
/dataquest/system/env/python3/lib/python3.4/site-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
   1407                 cur.execute(*args, **kwargs)
   1408             else:
-> 1409                 cur.execute(*args)
   1410             return cur
   1411         except Exception as exc:
DatabaseError: Execution failed on sql '
SELECT
    game_id,
    date,
    h_name,
    number_of_game
FROM game_log
LIMIT 5;
': database is locked

Any help?

Thanks so much!
Israel.

Hi @ieshatchuell ,

I would like to take a look at your Guided Project, please click the Download button at the top of the Jupyter Notebook interface in our platform.

This will download a .tar file that contains both your notebook file and the required datasets. Please attach this .tar file with your reply.

Best,
Sahil

Hi @Sahil,
thanks for response. I’ve been trying to download the notebook and the database (before writing this post) but it doesn’t work. When I click on the buttom, nothing happen.
Any advice?

Thank you!
Israel.

Hi @ieshatchuell,

I guess it’s due to the large database file in that project. Can you send me the .ipynb file using the below workaround?

Click on the Jupyter logo

Click on notebook folder

Click on notebook filenotebook_directory_files.png

Download the file using the File Menujupyter_file_download.png

Best,
Sahil

return conn.execute(query)

The issue is caused by the return statement. Please remove the return keyword from the above code so that it becomes like this:

def run_command(query):
    conn = sqlite3.connect(db)
    conn.execute(query)

Now delete the mlb.db file using the workflow I mentioned in the previous post. After that, run your code from start to finish and it will work. :slightly_smiling_face:

Best,
Sahil