ric*_*hie 5 python sqlite hdf5
Pandas DataFrame可以像这样转换为hdf5文件;
df.to_hdf('test_store.hdf','test',mode='w')
我有一个sqlite db文件,必须转换为hdf5文件然后我会通过pandas使用读取hdf5文件pd.read_hdf.
但首先我如何将python sqlite db转换为hdf5文件?
编辑:
我知道.read_sql在pandas 中使用该方法.但我想首先将db转换为hdf5.
这非常简单:使用熊猫!
pandas支持将数据直接从SQL数据库读取到DataFrame中.获得DataFrame后,您可以根据需要使用它.
简短的例子,取自文档:
import sqlite3
from pandas.io import sql
# Create your connection.
cnx = sqlite3.connect('mydbfile.sqlite')
# read the result of the SQL query into a DataFrame
data = sql.read_sql("SELECT * FROM data;", cnx)
# now you can write it into a HDF5 file
data.to_hdf('test_store.hdf','test',mode='w')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1507 次 |
| 最近记录: |