0

我在 google colab 中上传final_half.sqlite文件。在阅读文件时,它给了我如下错误。谁能告诉我如何解决这个问题?

DatabaseError: database disk image is malformed

我在google colab中上传了文件如下

import pandas as pd
import sqlite3
from google.colab import files
uploaded = files.upload()

我检查了上传文件的状态

for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
      name=fn, length=len(uploaded[fn])))

用户上传的文件“final_half.sqlite”,长度为 7208960 字节

for name, data in uploaded.items():
  with open('final_half.sqlite', 'wb') as f:
    f.write(data)
    print ('saved file', name)
    con = sqlite3.connect(name)
    print(con)
    sorted_data = pd.read_sql_query("""SELECT * FROM Reviews_half""", con)

错误:

DatabaseError                             Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/io/sql.py in execute(self, *args, **kwargs)
   1408             else:
-> 1409                 cur.execute(*args)
   1410             return cur

DatabaseError: database disk image is malformed
4

1 回答 1

0

更改这些行

for name, data in uploaded.items():
  with open('final_half.sqlite', 'wb') as f:
    f.write(data)
    print ('saved file', name)
    con = sqlite3.connect(name)

只是

con = sqlite3.connect('final_half.sqlite')

该文件已保存,您无需再次写入。

于 2018-05-17T20:47:20.703 回答