title: Reorder xmin, xmax, ymin, and ymax for each column in CSV file into new columns
body: <p>I am new to python, and am struggling with a calculation. I have several thousand rows of data in a CSV table in the following format:</p>
  <p><a href="https://i.stack.imgur.com/yQdqM.png" rel="nofollow noreferrer">Link to image table</a></p>
  <p>This data is in the wrong format in that several of my xmin/ymin values are higher than the xmax/ymax values (examples can be seen in the image link above). I need to create new columns and use either <code>numpy</code> or <code>pandas</code> to reorder the data so that they are in the correct format, such as using this code:</p>
  <pre><code>import numpy as np
  
  xmin_new = np.min(xmin, xmax)
  xmax_new = np.max(xmin, xmax)
  ymin_new = np.min(ymin, ymax)
  ymax_new = np.max(ymin, ymax)
  </code></pre>
  <p>The trouble is that I'm having trouble defining a column in a CSV and iterating through rows to do this. Can anyone suggest how I could modify this script to accomplish this?</p>
  <pre><code>import pandas
  import numpy as np
  import os
  import csv
  
  #Set cwd
  os.chdir(&quot;C:\\Users\\desired_directory&quot;)
  
  #Open desired csv file
  v = open(&quot;train.csv&quot;)
  r = csv.reader(v)
  row0 = r.next()
  
  #print header to look at file
  print row0
  
  row0.append('xmin_new')
  row0.append('xmax_new')
  row0.append('ymin_new')
  row0.append('ymax_new')
  
  #Check appends
  print row0
  
  xmin_new = np.min(xmin, xmax)
  xmax_new = np.max(xmin, xmax)
  ymin_new = np.min(ymin, ymax)
  ymax_new = np.max(ymin, ymax)
  
  #Errors occur here saying that the &quot;xmin_new&quot; column is undefined.
  #Also looking to save the file to the directory, but unsure of how to do this properly.
  </code></pre>