Я работал над фреймом данных (ранее извлеченным из таблицы с помощью SQLAlchemy), и теперь я хочу получить изменения, обновляющие эту таблицу.
Я сделал это очень неэффективным способом:
engine = sql.create_engine(connect_string)
connection = engine.connect()
metadata = sql.MetaData()
pbp = sql.Table('playbyplay', metadata, autoload=True, autoload_with=engine)
for i in range(1,len(playbyplay_substitutions)):
query_update = ('update playbyplay set Player_1_Visitor = {0}, Player_2_Visitor = {1} ,Player_3_Visitor = {2} ,Player_4_Visitor = {3} ,Player_5_Visitor = {4} where id_match = {5} and actionNumber = {6}'.format(playbyplay_substitutions.loc[i,'Player_1_Visitor_y'], playbyplay_substitutions.loc[i,'Player_2_Visitor_y'], playbyplay_substitutions.loc[i,'Player_3_Visitor_y'], playbyplay_substitutions.loc[i,'Player_4_Visitor_y'], playbyplay_substitutions.loc[i,'Player_5_Visitor_y'], playbyplay_substitutions.loc[i,'id_match'],playbyplay_substitutions.loc[i,'actionNumber']))
connection.execute(query_update)
playbyplay_substitutions
- это мой фрейм данных, playbyplay
- моя таблица, а остальные - это поля, которые я хочу обновить, или ключи в моей таблице. Я ищу более эффективное решение, чем то, которое у меня сейчас есть для SQLAlchemy, интегрированного с MySQL.