If have a sqlalchemy database and want to run an update query. I thought I could just use the same method that I also use for SELECT commands.
Here's my code:
disk_engine = create_engine('sqlite:///test.db')
chunksize = 20000
j = 0
index_start = 1
for df in pd.read_csv('test.csv', chunksize=chunksize,
iterator=True, encoding='utf-8'):
df.index += index_start
j+=1
df.to_sql('data', disk_engine, if_exists='append')
index_start = df.index[-1] + 1
...
##NOW I WANT TO UPDATE A ROW
ts = pd.read_sql_query('UPDATE data SET score = ROUND(score,1)', disk_engine);
But this throws an error:
result.pyc in _non_result(self, default) 918 if self._metadata is None: 919 raise exc.ResourceClosedError( --> 920 "This result object does not return rows. " 921 "It has been closed automatically.", 922 )
ResourceClosedError: This result object does not return rows. It has been closed automatically.
How can I update the database correctly?