title: Best way read/sort data on Excel, when column 1 is subject and column 2 is the data, in python
body: <p>I'm trying to figure out the best way to read data and put it into either a list of the format <code>List[subject][data for that subject]</code> a data frame or an array. I have provided an image of what the data should look like approximately on Excel. I am not a csd major but I find programming rather useful in my research. So far I have managed to import the data by using openpyxl into a list and then into an array, but it seems rather messy doing it this way. </p>
  
  <p>Below is my code for reading from the Excel file:</p>
  
  <pre><code>def read_cell (x_cord,y_cord,listofdata):
  
  list1 = [] #my a, b c cells
  currentcell_old = 0
  list2 = [] #my values to be added to the cell
  last_in_range = sheet.max_row + 1 #sheetmaxrow gives the ultimate row height
  list3 = [] #cell's name, object
  
  cellwrite = 0.0 #where our response is written at
  cellwrite_value = 0 #the values
  
  x=0 
  newcell = 0.0
  currentcell = 0.0
  ro[enter image description here][1]w=2
  nextcell = 0.0
  cellwrite = 0 #for iteration on count
  
  for i in range(1,last_in_range-1) :
      print(last_in_range)
      print(i)
      nextcell = (sheet.cell(row=i + x_cord, column=y_cord+1).value) #value volumetric next to (2,3)
  
      currentcell = (sheet.cell(row=i+ x_cord, column=y_cord).value) #cell we are on (2,3)
      newcell = (sheet.cell(row=i+ x_cord +1, column=y_cord).value) #name of the new cell to be examined (3,3)
  
      if i==1 : #if its step one then do this
          currentcell_old = currentcell
          list2.append(nextcell)
          list3.append(currentcell)
  
      if i&gt;=(last_in_range-3): #for last 3
          list2.sort()
          list2.append(nextcell)
  
      elif currentcell != currentcell_old : #if its changing to a new name do this, add the new name!
          list2.sort()
          list1.append(list2)
          list3.append(currentcell)
  
          currentcell_old = currentcell
          list2 = [] #delete a list, could also do del list2[:] but would affect other connected values
          list2.append(nextcell)
  
      elif currentcell == currentcell_old : #if its the same as the old name do this
          if currentcell == 'none':
              x=1
          else:
              list2.append(nextcell)
  
  
  return (list1 , list3)
  </code></pre>
  
  <p>Any comment is welcome!</p>
  
  <p><a href="https://drive.google.com/open?id=1lWdPMTszipqrZv1V5QCctnFg6ESz5_F5" rel="nofollow noreferrer">Link to my excel file simplified</a></p>