title: how to get the average of values for one column based on another column value in python (pandas, jupyter)
body: <p><a href="https://i.stack.imgur.com/PB5cB.png" rel="nofollow noreferrer">the image shows the test dataset I am using to verify if the right averages are being calculated.</a></p>
  
  <p>I want to be able to get the average of the corresponding values in the 'G' column based on the filtered values in the 'T' column.</p>
  
  <p>So I set the values for the 'T' coloumn based on which I want to sum the values in the 'G' column and then divide the total by the count to get an average, which is appended to a variable. 
  however the average is not correctly calculated. see below
  <a href="https://i.stack.imgur.com/SagHy.png" rel="nofollow noreferrer">screenshot</a></p>
  
  <pre><code>total=0
  g_avg=[]
  output=[]
  counter=0
  for i, row in df_new.iterrows():
      if (row['T'] &gt; 2):
          counter+=1
          total+=row['G']
      if (counter != 0 and row['T']==10):
          g_avg.append(total/counter)
          counter = 0
          total = 0
  
  print(g_avg)
  </code></pre>
  
  <p>below is a better set of data as there is repetition in the 'T' values so I would need a counter in order to get my average for the G values when the T value is in a certain range i.e. from 2am to 10 am etc 
  <a href="https://i.stack.imgur.com/5JTk2.png" rel="nofollow noreferrer">sorry it wont allow me to just paste the dataset so ive took a snippy of it</a></p>