title: Sort a list based on values from dataframe
body: <p>Is my approach here the right way to do it in Python?  As I'm new to Python, I appreciate any feedback you can provide, especially if I'm way off here.</p>
  
  <p>My task is to order a list of file names based on values from a dataset.  Specifically, these are file names that I need to sort based on site information.  The resulting list is the order in which the reports will be printed.</p>
  
  <p><strong>Site Information</strong></p>
  
  <pre><code>key_info = pd.DataFrame({
      'key_id': ['1010','3030','2020','5050','4040','4040']
      , 'key_name': ['Name_A','Name_B','Name_C','Name_D','Name_E','Name_E']
      , 'key_value': [1,2,3,4,5,6]
  })
  key_info = key_info[['key_id','key_name']].drop_duplicates()
  key_info['key_id'] = key_info.key_id.astype('str').astype('int64')
  </code></pre>
  
  <p><strong>Filenames</strong></p>
  
  <p>These are the file names I need to sort.  In this example, I sort by just the key_id, but I assume I could easily add a column to site information and sort it by that as well.</p>
  
  <pre><code>filenames = ['1010_Filename','2020_Filename','3030_Filename','5050_Filename','4040_Filename']
  </code></pre>
  
  <p><strong>Sorting</strong></p>
  
  <p>The resulting "filenames" is the final sorted list.</p>
  
  <pre><code>names_df = pd.DataFrame({'filename': filenames})
  names_df['key_id'] = names_df.filename.str[:4].astype('str').astype('int64')
  
  merged_df = pd.merge(key_info, names_df, on='key_id', how='right')
  merged_df = merged_df.sort_values('key_id')
  
  filenames = merged_df['filename'].tolist()
  </code></pre>
  
  <p>I'm looking for any solutions that might be better or more Pythonic.  Or, if there is a more appropriate place to post "code review" questions.</p>