LANGUAGE=PYTHON.PY My task is to pull the temperature from a weather data stream bi-monthly (the 1st and the 15th) and f

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

LANGUAGE=PYTHON.PY My task is to pull the temperature from a weather data stream bi-monthly (the 1st and the 15th) and f

Post by answerhappygod »

LANGUAGE=PYTHON.PY
My task is to pull the temperature from a weather data stream
bi-monthly (the 1st and the 15th) and figure out the temperature
variance over time. I can read data, but I have been hacking at the
code for a while with all sorts of errors. Right now, I am just
printing out the result of my code that reads the file and filters
the data for the temperatures on the 1st and 15th dates. There
should only be a handful of values, but it includes a big list. Can
you figure out how to get just the data on these two dates and then
maybe make the commented-out code work?
PYTHON.PY
def readWeatherData(filename):
file = open(filename, 'r')
file.readline() # skip the header
tempsByStation = []

for line in file:
tokens = line.split(',')
stationId = tokens[0][1:-1]
date = tokens[3][1:-1]
tavg = tokens[10][1:-1]
if len(tavg) > 0:
print(line)

tempsByStation.append((stationId, date, tavg))
return tempsByStation
def getDayOfMonth(date):
tokens = date.split('-')
return tokens[2]
def getBiMonthlyTemperatureVariance(data):
weeklyTemps = []
for entry in data:
day = getDayOfMonth(entry[1])
if day == 1 or 15:

weeklyTemps.append(entry[2])
return weeklyTemps
data = readWeatherData("2466150.csv")
temperatures = getBiMonthlyTemperatureVariance(data)
print(temperatures)
#for index in range(len(temperatures) - 1):
# variance = temperatures[index + 1] -
temperatures[index]
# print (variance)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply