title: Python Mysql Update Data only if there are new values
body: <p>I catch some data from an url and have around 2400 rows of data in a dataframe.</p>
  <pre><code>data = pd.DataFrame(dictlist)
  df = data.sort_values([&quot;Rank&quot;],ascending=True,inplace=True)
  
  
  connection = pymysql.connect(host=&quot;localhost&quot;,    # your host, usually localhost
                   user=&quot;crypto&quot;,         # your username
                   passwd=&quot;abcd&quot;,  # your password
                   db=&quot;crypto&quot;)        # name of the data base
  
  cursor=connection.cursor()
      
  sql = &quot;REPLACE INTO coins(Rank,Name,Price) VALUES ( %s,%s,%s)&quot;
      
  for i in range(0,len(df)):
      
      cursor.execute(sql,(str(df[&quot;Rank&quot;][i]),str(df[&quot;Name&quot;][i]),str(df[&quot;Price&quot;][i])))#,str(Supply[i]),str(Volume[i]),str(Change24[i]),str(Change7[i]),str(ATH[i]),str(toATH[i])))
      connection.commit()
  </code></pre>
  <p>I want to update the values Rank and Price if the Name is already in the Database. I tried REPLACE and also UPDATE ON KEY DUPLICATE but both are not working. It seems that the data append to the old data in the database.</p>
  <p>First Run 2400 Values are in DB
  Second Run 4800 Values
  ...</p>
  <p>I want only Update existing Values (based on Name) and if they are not in the DB it should be created a new row.</p>
  <p>Also it seems that my sort _values command not works. It is still unsorted in the DB</p>