[Tutor] For loops with lists
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Jul 19 06:20:55 EDT 2021
On 19/07/2021 03:12, sage pavlovich wrote:
> 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
rather than you try to describe what/where you think the problem
is just include the full error message - it contains all the
information we need(in conjunction with the code of course!)
That way we don't need to guess...
> timedata = data
I'm not sure why you are doing that?
Why not just all it timeata to start with?
> timedata['Datetime'] = pd.to_datetime(data['Date'] + ' ' + data['HH:MM'],> format='%d/%m/%y %H:%M') # convert date and time
And this is now very confusing since you are referring to timedata and
data in the same line but they are the same object! Use one name or the
other but not both. That's a recipe for madness when it comes to debugging.
> timedata = timedata.set_index('Datetime') # set as index
> del timedata['Date'] # remove date column
> del timedata['HH:MM'] # remove time column
And now you overwrite the timedata so it points to something else.
> timedata.index = timedata.index.map(lambda t: t.replace(year=2020)) #
> overwrite year
Are you sure you mean to replace the index with the result of the map?
That sounds dangerous to me!
> 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)
No colon after the loop, this is likely your syntax error
> 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])
And no indentation of the block either...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list