title: divide/split a row into multiple rows in pandas data frame
body: <p>I have the following dataset; </p>
  
  <pre><code>     Subject                                         Student ID  Student Number
  0      Cit11  [S95, S96, S97, S98, S99, S100, S101, S102, S1...              45
  1  EngLang11  [S95, S96, S97, S98, S99, S100, S101, S102, S1...              45
  2   EngLit11  [S110, S111, S112, S113, S114, S115, S116, S11...              21
  3      Fre11  [S95, S96, S97, S99, S100, S101, S102, S103, S...              26
  4      Ger11  [S114, S115, S116, S117, S118, S124, S125, S12...              13
  5      His11  [S95, S96, S97, S98, S99, S100, S101, S102, S1...              45
  6      Mat11  [S95, S96, S97, S98, S99, S100, S101, S102, S1...              45
  7      Spa11  [S95, S97, S98, S99, S100, S102, S103, S104, S...              23
  </code></pre>
  
  <p>where <code>'Student Number'</code> is the total number of <code>'Student ID'</code> in each <code>'Subject'</code>.</p>
  
  <p>Let's say the maximum <code>'Student Number'</code> should be 30 (classroom_Max_Capacity returns the value), and the following code returns indexes where <code>'Student Number'</code> exceeds the maximum number.</p>
  
  <pre><code>idx = filtered_Group[filtered_Group['Student Number'] &gt; classroom_Max_Capacity].index.tolist()
  Output: [0, 1, 5, 6]
  </code></pre>
  
  <p>I am wondering if I can split those rows into two by changing <code>'Subject'</code> name and <code>'Student ID'</code> to fit the maximum student number; for example,</p>
  
  <pre><code>Subject                                         Student ID  Student Number
  0      Cit11_1  [S95, S96, S97, S98, S99, S100, S101, S102, S1...              30
  1      Cit11_2  [S110, S115, S116...                                           15
  2  EngLang11_1  [S95, S96, S97, S98, S99, S100, S101, S102, S1...              30
  3  EngLang11_2  [S110, S115, S116...                                           15
  4     EngLit11  [S110, S111, S112, S113, S114, S115, S116, S11...              21
  5        Fre11  [S95, S96, S97, S99, S100, S101, S102, S103, S...              26
  6        Ger11  [S114, S115, S116, S117, S118, S124, S125, S12...              13
  7      His11_1  [S95, S96, S97, S98, S99, S100, S101, S102, S1...              30
  8      His11_2  [S110, S115, S116...                                           15
  9      Mat11_1  [S95, S96, S97, S98, S99, S100, S101, S102, S1...              30
  10     Matt11_2 [S110, S115, S116...                                           15
  11       Spa11  [S95, S97, S98, S99, S100, S102, S103, S104, S...              23
  </code></pre>
  
  <p>Is this even possible by not specifically writing modified <code>'Subject'</code> name to add in the data frame?</p>
  
  <p>--edit</p>
  
  <p>I attempted to solve the problem by doing something like;</p>
  
  <pre><code>filtered = filtered_Group.iloc[idx]
  
  student_list = filtered['Student ID'].explode().str.split(', ')
  subject_list = filtered['Subject']
  
  for i in idx:
      for number in range(classroom_Max_Capacity):
          df.append({temp_subject_list[i]: temp_student_list[number]})
  </code></pre>
  
  <p>But of course, this doesn't work so any help would be much appreciated. </p>