[Tutor] For loops with lists

sage pavlovich sagepav at gmail.com
Sun Jul 18 22:12:19 EDT 2021


   Hey I'm trying to do calculate Tzone finding a final result for a list of
   values from 0-8760. It is saying my syntax is wrong but not sure why. Any
   tips? The last section of code is where the errors are occuring



   import pandas as pd # import pandas data manipulation library

   import numpy as np # import numpy numerical library

   import matplotlib.pyplot as plt # import matplotlib plotting library

   import seaborn # import seaborn for advanced plotting



   data = pd.read_csv('weatherdata.csv') # load the weather file into a
   dataframe called 'data'

   print(data)



   timedata = data

   timedata['Datetime'] = pd.to_datetime(data['Date'] + ' ' + data['HH:MM'],
   format='%d/%m/%y %H:%M') # convert date and time

   timedata = timedata.set_index('Datetime') # set as index

   del timedata['Date'] # remove date column

   del timedata['HH:MM'] # remove time column

   timedata.index = timedata.index.map(lambda t: t.replace(year=2020)) #
   overwrite year

   print(timedata)



   T_air = timedata['Dry Bulb Temp']

   RH = timedata['Relative Humidity']

   x = list(range(0,12))

   monthly_Temp = timedata['Dry Bulb Temp'].resample('M').mean()

   monthly_RH = timedata['Relative Humidity'].resample('M').mean()



   fig, ax1 = plt.subplots()



   ax2 = ax1.twinx()

   ax1.plot(x, monthly_Temp, 'g-')

   ax2.plot(x, monthly_RH, 'b-')



   ax1.set_xlabel('Months of the Year')

   ax1.set_ylabel('Temperature', color='g')

   ax2.set_ylabel('Relative Humidity', color='b')

   pltojb = plt.title('Temperature vs Humidity')

   plt.grid(True)

   plt.show()



   Q_North = timedata['Total Solar North'] # access total solar north energy
   column and make list

   Q_South = timedata['Total Solar South'] # access the total solar south
   energy column and make list

   Q_North.plot()

   plt.ylabel('Solar Gains, W') # label the y axis

   plt.title('Northern Solar Gains 2020') # add a title

   plt.grid()



   Wind_Direction = timedata['Wind Direction']

   South_or_North_Wind = timedata[((Wind_Direction >= 135) & (Wind_Direction
   <= 225)) | ((Wind_Direction >= 315) | (Wind_Direction <= 45))]

   Windspeed=South_or_North_Wind['Wind Speed']

   print (Windspeed)

   Windspeed.plot()



   for i in range(0,8760)

   print (i)

   P1 = (0.8*1.2)*((Windspeed[i]^2)/2)

   P2 = (-0.5*1.2)*((Windspeed[i]^2)/2)

   Vvent[i] = (sqrt(15)/5)*(sqrt(P1[i]-P2[i]))

   print (Vvent)

   Qvent[i] = (1.2*Vvent[i])*(T_air[i]-Tzone[i])

   Tzone[i] = (Tair[i]+(Q_South[i]+Q_North[i])+109.333)/(1.2*Vvent[i])




More information about the Tutor mailing list