title: Assign the response times to each question in a Moodle questionnaire using groupby pandas
body: <p>I´m trying to assign the time it takes to answer each question from a Moodle post-Process log. I have organized the data in the following way</p>
  <p>Example DATA (2 students and 4 questions)</p>
  <pre><code>original= [{&quot;Student&quot;:&quot;S1&quot;,&quot;Send&quot;:&quot;0:00:00&quot;},{&quot;Student&quot;:&quot;S1&quot;,&quot;Send&quot;:&quot;0:01:00&quot;},{&quot;Student&quot;:&quot;S1&quot;,&quot;Send&quot;:&quot;0:02:00&quot;},{&quot;Student&quot;:&quot;S1&quot;,&quot;Send&quot;:&quot;0:04:00&quot;},{&quot;Student&quot;:&quot;S1&quot;,&quot;Send&quot;:&quot;0:05:00&quot;},{&quot;Student&quot;:&quot;S2&quot;,&quot;Send&quot;:&quot;0:00:00&quot;},{&quot;Student&quot;:&quot;S2&quot;,&quot;Send&quot;:&quot;0:02:00&quot;},{&quot;Student&quot;:&quot;S2&quot;,&quot;Send&quot;:&quot;0:04:00&quot;},{&quot;Student&quot;:&quot;S2&quot;,&quot;Send&quot;:&quot;0:04:00&quot;},{&quot;Student&quot;:&quot;S2&quot;,&quot;Send&quot;:&quot;0:05:00&quot;}]
  df = pd.DataFrame(original)
  df['Send'] =pd.to_datetime(df['Send'], format='%H:%M:%S') - pd.to_datetime(df['Send'], format='%H:%M:%S').dt.normalize()
  df['diff'] = df.sort_values(['Student','Send']).groupby('Student')['Send'].diff()
  df
     Send    Student     diff
  0 00:00:00      S1      NaT
  1 00:01:00      S1 00:01:00  # Send[1]-Send[0]= S1 Time response to P1
  2 00:02:00      S1 00:01:00
  3 00:04:00      S1 00:02:00
  4 00:05:00      S1 00:01:00
  5 00:00:00      S2      NaT
  6 00:02:00      S2 00:02:00
  7 00:04:00      S2 00:02:00
  8 00:04:00      S2 00:00:00
  9 00:05:00      S2 00:01:00
  </code></pre>
  <p>And I'm looking for a solution like this: a new dataframe that collects the student name and the time of response (Column diff) for each question. Something like that</p>
  <pre><code>  Student | P1      | P2      | P3      | P4      
   ---------|---------|---------|---------|--------- 
    S1      | 0:01:00 | 0:01:00 | 0:02:00 | 0:01:00 
    S2      | 0:02:00 | 0:02:00 | 0:00:00 | 0:01:00 
  </code></pre>
  <p>Considerations:</p>
  <ul>
  <li>in the example data, the first value of each student (index 0 for S1 and index 6 for S2)  is the time at which the question was displayed</li>
  <li>the second value for each student (index 2 for S1) is the moment the student saves the first answer.</li>
  <li>The response time is therefore 0:01:00 - 0:00:00 (Send[1]-Send[0])</li>
  </ul>
  <p>I'm sure it's a simple problem, but right now I'm stuck and I don't know how to get out of this impasse. Any help will be welcome</p>