我有一个大型数据集,需要根据某些列的值来设置子集。我想从这个子集创建另一个数据库。我如何用Python中的sqlite3做到这一点?
The column from which I want to compare to get the subset contain date in the format of YYYYMMDD e.g. 20120429.
I want to get the observation before a certain date.
另外,如何根据另一列的值来赢得并计算某些列的平均值?
谢谢
答案 0 :(得分:1)
您可以attach
将新数据库文件添加到已存在的SQLite连接(已打开现有数据库),然后只需使用相应的insert
语句复制所需的行,即可对表进行处理在附加的数据库中使用DB别名:
attach 'newdb.sqlite' as newdb;
-- create table goes here if necessary
insert into newdb.table
select * from table where date < ...;