Page 1 of 1

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

Posted: Fri May 20, 2022 3:40 pm
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)