title: Split dataframe according to column value and export to different Excel worksheets
body: <p>Source used before asked:</p>
  
  <p><a href="https://stackoverflow.com/questions/36973867/pandas-iterate-through-a-list-of-dataframes-and-export-each-to-excel-sheets?rq=1">Pandas: Iterate through a list of DataFrames and export each to excel sheets</a></p>
  
  <p><a href="https://stackoverflow.com/questions/19790790/splitting-dataframe-into-multiple-dataframes">Splitting dataframe into multiple dataframes</a></p>
  
  <p>I have managed to do all of this:</p>
  
  <pre><code># sort the dataframe
  df.sort(columns=['name'], inplace=True)
  # set the index to be this and don't drop
  df.set_index(keys=['name'], drop=False,inplace=True)
  # get a list of names
  names=df['name'].unique().tolist()
  # now we can perform a lookup on a 'view' of the dataframe
  joe = df.loc[df.name=='joe']
  # now you can query all 'joes'
  </code></pre>
  
  <p>I have managed to make this work - <code>joe = df.loc[df.name=='joe']</code> and it gave the exact result what I was looking for. </p>
  
  <p>As solution to make it work for big amount of data I found this potential solution.</p>
  
  <pre><code>writer = pandas.ExcelWriter("MyData.xlsx", engine='xlsxwriter')
  List = [Data , ByBrand]
  for i in List:
          i.to_excel(writer, sheet_name= i)
  writer.save()
  </code></pre>
  
  <p>Currently I have:</p>
  
  <pre><code>teacher_names = ['Teacher A', 'Teacher B', 'Teacher C']
  </code></pre>
  
  <p>df =</p>
  
  <pre><code>              ID   Teacher_name      Student_name
  Teacher_name                                                         
  Teacher A     1.0  Teacher A         Student 1 
  Teacher A     NaN  Teacher A         Student 2  
  Teacher B     0.0  Teacher B         Student 3 
  Teacher C     2.0  Teacher C         Student 4 
  </code></pre>
  
  <p>If I use - <code>test = df.loc[df.Teacher_name=='Teacher A']</code> - Will receive exact result.</p>
  
  <p><strong>Question:</strong> How to optimise that it will automatically save the "test" result to (for each teacher separate) excel file ( <code>.to_excel(writer, sheet_name=Teacher_name</code> ) with teacher name, and will do it for all the existing in the database teacher?</p>