Py学习  »  Python

python-将数据帧追加到sqlite3表中,是BLOB而不是timestamp?

Sid • 5 年前 • 1587 次点击  

我试图将数据从大熊猫数据文件追加到SQLite数据库中的现有表中。在我尝试使用资源管理器查看数据的过程之后,它显示为 BLOB . 当我试图从数据库中读取pandas时,会得到错误信息:

将数据帧读入sqlite表:

# the dtype of timestamp column is datetime64[ns]
query = 'insert or replace into bnffut (timestamp,close,bid,ask) values (?,?,?,?)'
conn.executemany(query, df.to_records(index=False))
conn.commit()

select_statement = 'select * from '+ 'bnf' +'fut order by timestamp DESC limit 80000'
m1df = pd.read_sql(select_statement, conn)

1-如何将数据添加到sqlite表以确保它不是 团块 但时间戳本身呢?

-----编辑-----

我已经找到了解决我特殊问题的办法。

对于sqlite3列,dtype太长,我将timestamp列更改为:

df['timestamp'] = df['timestamp'].astype(str)

现在它显示了正确的日期时间,选择不是问题。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54955
 
1587 次点击  
文章 [ 1 ]  |  最新文章 5 年前