dataframe to sqlite写入读取数据库

Posted The_Chain

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dataframe to sqlite写入读取数据库相关的知识,希望对你有一定的参考价值。

import tushare as ts

import pandas as pd

import numpy as np

import sqlite3

pf=ts.get_hist_data(‘600848‘)

con=sqlite3.connect(‘c:\desktop\stockdata.db‘)#如果路径里面没有这个数据库,会自动创建

c=con.cursor()

pf.to_sql(‘data‘,con=con,if_exists=‘append‘,index=False)

sql="select * from data"

test=pd.read_sql(sql,con)#完成数据库的查询读取到数据框dataframe 中

 

以上是关于dataframe to sqlite写入读取数据库的主要内容,如果未能解决你的问题,请参考以下文章

使用NPOI读取Excel数据并写入SQLite

写入 MySQL 时查询 sqlite_master 表时出现 to_sql() 错误

将图像读取和写入 SQLite DB 以供 iPhone 使用

是否合法写入并集中的字节数组并从int读取以在MISRA C中转换值?

使用 fmdb 写入 sqlite db?

iOS 读取数据时收到 Sqlite 错误数据库被锁定