【问题标题】:Load and use sqlite file in google colab在 google colab 中加载和使用 sqlite 文件
【发布时间】:2019-05-14 17:07:53
【问题描述】:
print ('Files in Drive:')

!ls drive/AI`

'database.sqlite' 文件已存在于驱动器中。 当我在 Google Colab 中运行上述代码时,很明显我的 sqlite 文件存在于我的驱动器中。但是每当我对这个文件运行一些查询时,它就会说

# using the SQLite Table to read data.
con = sqlite3.connect('database.sqlite') 

#filtering only positive and negative reviews i.e. 
# not taking into consideration those reviews with Score=3
filtered_data = pd.read_sql_query("SELECT * FROM Reviews WHERE Score !=3",con)

DatabaseError: sql 'SELECT * FROM Reviews WHERE Score != 3' 执行失败:没有这样的表:Reviews

【问题讨论】:

  • 如果您提供虚假文件名,connect 是否会引发错误? (一种可能性是您需要将工作目录更改为/content/drive/My\ Drive/。)另外,您如何确认数据库中存在Reviews 表? (另一种可能是报错信息正确,没有这个表。)
  • @BobSmith 谢谢!将目录更改为 /content/drive/My\ Drive/ 有效。我使用 %cd / 而不是 %cd ./ 来更改目录。

标签: sqlite google-colaboratory


【解决方案1】:

上传文件后,单击左侧的导航窗格。在“文件”选项卡下,右键单击您上传的文件并选择“复制路径”。在连接中使用这个复制的路径:

con = sqlite3.connect('content/database.sqlite') 

【讨论】:

    猜你喜欢
    • 2022-11-07
    • 2020-06-07
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 2020-09-27
    • 2020-02-05
    • 1970-01-01
    相关资源
    最近更新 更多