def_replace_data(df, keys =['columnId']):
df = df.where(df.notnull(),None)
conn = get_db_conn()
cur = conn.cursor()
sql =f"""INSERT INTO alg_cluster_info({','.join(df.columns)})
VALUES({','.join(['%s']*len(df.columns))}) on duplicate key update """+ \
','.join([f"{i} = values({i})"for i in df.columns if i notin keys])print(sql)try:
cur.executemany(sql,[tuple(x)for x in df.values])
conn.commit()except TypeError:
conn.rollback()finally:
cur.close()
conn.close()