title: Compare two files if they both match first column then replace the values of column 2 and 3 (Python)
body: <p>There are two files. If the ID number matches both files, then I want only the value 1 and value 2 from File2.txt , Please let me know if my question is unclear</p>
  
  <pre><code>File1.txt
  
  
  ID Number   Value 1     Value 2     Country 
  0001        23            55        Spain
  0231        15            23        USA     
  4213        10            11        Canada
  7541        32            29        Italy
  
  File2.txt
  
  0001        5       6
  0231        7       18
  4213        54      87
  5554        12      10
  1111        31      13
  6422        66      51
  </code></pre>
  
  <p>The output should look like this. </p>
  
  <pre><code>ID Number   Value 1     Value 2     Country 
  0001          5           6         Spain
  0231          7          18         USA     
  4213          54         87         Canada
  7541          32         29         Italy
  </code></pre>
  
  <p>New example:</p>
  
  <pre><code>File3.txt
  
  #ID CAT CHN LC SC LATITUDE LONGITUDE 
  20022 CX 21 --   4  32.739000  -114.635700 
  01711 CX 21 --   3  32.779700  -115.567500
  08433 CX 21 --   2  31.919930  -123.321000
  
  
  File4.txt
  
  20022,32.45,-114.88
  01192,32.839,-115.487
  01711,32.88,-115.45
  01218,32.717,-115.637
  
  output
  #ID CAT CHN LC SC LATITUDE LONGITUDE 
  20022 CX 21 --   4  32.45  -114.88 
  01711 CX 21 --   3  32.88  -115.45
  08433 CX 21 --   2  31.919930  -123.321000
  </code></pre>
  
  <p>Code I got so far</p>
  
  <pre><code>f = open("File3.txt", "r") 
  x= open("File4.txt","r")
  
  df1 = pd.read_csv(f, sep=' ', engine='python')
  df2 = pd.read_csv(x, sep=' ', header=None, engine='python')
  
  df2 = df2.set_index(0).rename_axis("#ID")
  df2 = df2.rename(columns={5:'LATITUDE', 6: 'LONGITUDE'})
  df1 = df1.set_index('#ID')
  df1.update(df2)
  print(df1)
  </code></pre>