title: Any advice for how to structure a function that calculates the min and max of another list, for each day (24 rows of data)?
body: <p>I am working with a csv file of hourly temperature data for a specific location for a year. From there I made a dataframe in pandas with the following lists: DOY (24 for every day), Time (in minutes; 0, 60, 120, etc.), and temperature. </p>
  
  <p>These data are serving as input data for a model that I have in Python (Jupyter notebooks, running on iOS) that predicts animal body temperatures when solving for a bunch of biophysical heat flux equations. For that model, I have a function that has the arguments of min and max temperature for every day. In the csv file, every day has 24 rows of data since they're giving hourly temperatures. I need to be able to iterate through this csv file and select the minimum and maximum temperature value for the day before current day [i-1], the current day [i], and the following day [i+1] in another function that I already have. Does anyone have suggestions for how to set up those functions? I'm still rather new to Python (&lt; 1 year experience) so any help would be really appreciated! :)</p>
  
  <p>Edit to clarify: </p>
  
  <pre><code>import math
  import itertools
  %pylab inline 
  import matplotlib as plt
  
  
  import pandas as pd
  import numpy as np
  %cd "/Users/lauren/Desktop"
  
  Ta_input = pd.DataFrame(pd.read_csv("28Jan_Mesa_Ta.csv"))
  Ta_input.columns = ['', 'doy', 'time', 'Ta'] 
  Ta_input.to_numpy()
  
  doy =list(Ta_input['doy'])
  time=list(Ta_input['time'])
  Ta=list(Ta_input['Ta'])
  
  micro_df = pd.DataFrame(list(zip(doy,time, Ta)),
                  columns=['doy','time', 'Ta'])
  print(micro_df)
  
  ##### Below is the readout showing what the df looks like ###
  
  Populating the interactive namespace from numpy and matplotlib
  /Users/lauren/Desktop
        doy  time        Ta
  0       1     0  4.434094
  1       1    60  4.383863
  2       1   120  4.115001
  3       1   180  3.831146
  4       1   240  3.537708
  ...   ...   ...       ...
  8755  365  1140  6.478684
  8756  365  1200  5.744720
  8757  365  1260  5.212801
  8758  365  1320  4.568695
  8759  365  1380  4.398663
  
  [8760 rows x 3 columns]
  /usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/IPython/core/magics/pylab.py:160: UserWarning: pylab import has clobbered these variables: ['time', 'polyint', 'plt', 'insert']
  `%matplotlib` prevents importing * from pylab and numpy
    "\n`%matplotlib` prevents importing * from pylab and numpy"
  
  
  </code></pre>
  
  <p>I have these functions</p>
  
  <pre><code>def anytime_temp(t,max_t_yesterday,min_t_today,max_t_today,min_t_tomorrow):
      #t = time
      #i = today
      #i-1 = yesterday
      #i+1 = tomorrow
      #Tn = daily min
      #Tx = daily max
      if 0.&lt;=t&lt;=5.:
          return max_t_yesterday*Gamma_t(t) + min_t_today*(1-Gamma_t(t))
      elif 5.&lt;t&lt;=14.:
          return max_t_today*Gamma_t(t)+ min_t_today*(1-Gamma_t(t))
      else:
          return max_t_today*Gamma_t(t)+ min_t_tomorrow*(1-Gamma_t(t))
  
  
  # Rabs = amount of radiation absorbed by an organism    
  def Rabs(s,alpha_s,h,lat,J,time,long,d,tau,alt,rg,alpha_l,max_t_yesterday,min_t_today,max_t_today,min_t_tomorrow,eg,Tave,amp,z,D):
      if math.cos(zenith(latitude,julian,time,longitude)) &gt; 0.:
          return s*alpha_s*(Fh(h,lat,J,time,long,d)*(hS(J,lat,time,long,tau,alt))+0.5*Sd(J,lat,time,long,tau,alt)+0.5*Sr(rg,J,lat,time,long,tau,alt)) + 0.5*alpha_l*(Sla(anytime_temp(time,max_t_yesterday,min_t_today,max_t_today,min_t_tomorrow)) + Slg(eg,Tzt(Tave,amp,z,D,time))) 
      else:
          return 0.5*alpha_l*(Sla(anytime_temp(time,max_t_yesterday,min_t_today,max_t_today,min_t_tomorrow)) + Slg(eg,Tzt(Tave,amp,z,D,time))) 
  </code></pre>
  
  <p>...which both take maximum temperature yesterday, minimum and maximum temperature today, and minimum temperature tomorrow as inputs. My code is set up to run with me just setting those values to be single numbers (e.g., min_t_today = 25.). But now that I have a list of hourly temperatures for the entire year, I am trying to figure out the best way to either modify these functions, or define new functions that I could call in these functions to allow me to pull the minimum and maximum temperature values for each specific DOY (day of year, which is another list in my df). </p>
  
  <p>In other words, my csv file has hourly temperatures for every DOY, so 24 temps per day. I need to iterate through to calculate and call on the min and max temperatures for a given day in these functions. Any tips would be helpful! Thanks!</p>