merijn van der leek
asked on
Finding a heat wave in a csv
Hey i have a assignment where i have to find a heatwave out of a csv. We can call something a heat wave f there is a period of at least 5 days where the temprature is 25 degrees or more and if in this period there are 3 days with a tempature of 30 degrees or more.
I need to print the first year where a heatwave occured. Example output: 2019
These are the first lines of the csv:
STAID,SOUID,DATE,TX,Q_TX
162,100522,19010101,-31,0
162,100522,19010102,-13,0
162,100522,19010103,-5,0
162,100522,19010104,-10,0
162,100522,19010105,-18,0
162,100522,19010106,-78,0
DATE is the date in the format year month day
Q is the temprature we are looking for times ten. ( so the temprature is Q/10)
I wrote some code but with this code i cant look if the period has 3 three days with 30 degrees or more. This is the code.
Can anyone help me with this?
I need to print the first year where a heatwave occured. Example output: 2019
These are the first lines of the csv:
STAID,SOUID,DATE,TX,Q_TX
162,100522,19010101,-31,0
162,100522,19010102,-13,0
162,100522,19010103,-5,0
162,100522,19010104,-10,0
162,100522,19010105,-18,0
162,100522,19010106,-78,0
DATE is the date in the format year month day
Q is the temprature we are looking for times ten. ( so the temprature is Q/10)
I wrote some code but with this code i cant look if the period has 3 three days with 30 degrees or more. This is the code.
import csv
with open("climate.csv", "r" ) as csvFile:
reader = csv.DictReader(csvFile)
heat_wave = []
heat_date = []
heat_counter = 0
for row in reader:
row_value = int(row['TX']) / 10
if row_value < 25 and heat_counter > 5:
heat_wave.append()
heat_date.append()
if row_value > 24:
heat_counter += 1
else:
heat_counter = 0
Can anyone help me with this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
please attach the full csv
ASKER
Hey i cant attacht the full csv bc its on the homework module itself. But every line of csv looks like the sample i send.
doesn't matter you have the solution.. cheers
ASKER