Search code examples
numpynested-loopscumsum

Nested for loops to calculate max. temperature from a csv


I'm starting a class on advanced data structures and I'm struggling to answer the problems shown in the image below.The NYC_temperature.csv has hourly temperatures and you have to calculate it by day to then show what was the warmest 30-day period

The Problems I have to solve


Solution

  • for i in range(len(data)-24*30-1):
        temp = 0
        for j in range(i, i+30):
            temp += data[j]
        maxtemp = max(temp, maxtemp)