title: Mysql statement into Python Pandas WHERE LIKE ORDER BY LIMIT
body: <p>I have two tables in a Mysql database one called Prefixes and the other called Calls. Prefixes holds 180,000 international telephone prefixes along with the associated county name and provider e.g. 9375, Afghanistan - Mobile - AT, 9370, Afghanistan - Mobile - AWCC. I've written a Mysql Statement that allows me to check a phone number against the prefixes and select out the prefix that matches the number most accurately. For example when I run the statement below</p>
  <p>select * from prefixes
  where
  '937541550' like CONCAT(prefix , '%')<br />
  #ORDER BY prefix DESC
  #LIMIT 1;</p>
  <p>It returns 9375, Afghanistan - Mobile - AT. If I run this statement</p>
  <p>select * from prefixes
  where
  '937741550' like CONCAT(prefix , '%')<br />
  #ORDER BY prefix DESC
  #LIMIT 1;</p>
  <p>It returns 9370, Afghanistan - Mobile - AWCC.</p>
  <p>The Calls table has around 500,000 rows in it, each contacting separate call details - number dialled, Call Duration, cost etc.</p>
  <p>I'm trying to do the following:-</p>
  <p>Firstly convert this statement so it will run in Python 3 Pandas. Secondly I want to pass the phone number of a row into the statement, select the best fitting prefix and then to finally add the call duration of the call to the individual prefix.</p>
  <p>Once the program has run all the call durations will have been allocated to each prefix, so I can analyse which prefixes are being used and how much volume is going to each. The Calls table includes a duration column that contains the call length in minutes and the Prefixes table has a column for call duration. My thoughts were to capture the current rows call length and then add that to the existing duration against the appropriate prefix.</p>
  <p>I'm new to python and would appreciate direction.</p>