Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 只合并SQLite数据库中的新数据_Python_Sql_Pandas_Sqlite_Dataframe - Fatal编程技术网

Python 只合并SQLite数据库中的新数据

Python 只合并SQLite数据库中的新数据,python,sql,pandas,sqlite,dataframe,Python,Sql,Pandas,Sqlite,Dataframe,我是SQL的绝对新手,刚刚开始使用它。我有一个包含股票价格和日期的SQLite数据库 通过API,我可以读取最新的股票价格,并希望更新我的数据库,只添加带有新日期的新价格。但是我想把旧的保存在数据库里。我将它们作为数据帧从API中获取。我的API正在返回重复项,我不希望数据库中有重复项 我使用Python3.6和sqlite3作为引擎 以下是数据中的一组数据示例: 1. open 2. high 3. low 4. close 5. volume

我是SQL的绝对新手,刚刚开始使用它。我有一个包含股票价格和日期的SQLite数据库

通过API,我可以读取最新的股票价格,并希望更新我的数据库,只添加带有新日期的新价格。但是我想把旧的保存在数据库里。我将它们作为数据帧从API中获取。我的API正在返回重复项,我不希望数据库中有重复项

我使用Python3.6和sqlite3作为引擎

以下是数据中的一组数据示例:

                     1. open  2. high  3. low  4. close  5. volume
date                                                              
2020-04-09 16:00:00  571.925   573.01  571.73    573.01   117287.0
2020-04-09 15:59:00  572.000   572.00  571.45    572.00    56954.0
2020-04-09 15:58:00  571.450   572.00  571.28    571.90    63987.0
2020-04-09 15:57:00  571.560   572.00  571.26    571.42    50978.0
2020-04-09 15:56:00  570.990   571.61  570.58    571.49    30975.0
我厌倦了他提出的解决方案。但我有一个错误:

KeyError: Index(['date'], dtype='object')
使用的代码是:

df_new=clean_df_db_dups(data, tablename, conn, ['date'])
print('New:',df_new.head())

任何帮助都很好。这只是我的第二个Stackoverflow帖子,所以如果我做了一些不对的事情,请告诉我

您可以使用which,它有一个名为if_exists的参数,如果数据库中已经存在该表,则该参数会预期该行为,您可以使用if_exists=append,如果您已经拥有该表,它将只追加pandas数据框。

基本上可以,但我的API中有重复项,必须将其过滤掉。如果您的意思是这样,您可以使用pandas drop_duplicates将重复项删除到数据框中。但是,如果您想要在数据帧中使用唯一的值,我建议您阅读以下内容:好的,谢谢,但是有没有直接使用sqlite3模块的可能解决方案?我个人不知道,对不起!好的,没问题。我尝试了这个解决方案,但问题中出现了一个错误