-2
I want to calculate the temperature average of each month of the year using a function. It’s not working. Follow the code I tried
import pandas as pd
tabela = pd.read_csv('DadosClimaticos2018Londrina.csv', sep =';')
tabela['Mes'] = pd.DatetimeIndex(tabela['Data'], yearfirst = True).month
tabela.to_csv('novo.csv',sep = ';', index = False)
def mediatemp(soma):
soma = 0
quant = 0
for i in range(len(tabela)):
linha= tabela.iloc[i]
temp = linha['Temperatura']
soma = soma + temp
quant = quant + 1
media = temp/quant
return media
print(mediatemp)
See if this solves what you want
– lmonferrari
Not knowing how the data is in your spreadsheet is difficult. But you have tried using the
df.mean()
? It is a native function of Pandas to calculate the average– Evilmaax
Another thing: You seem to be dividing the gross column of temperature by the amount of days. You need to sum up the temperature column first.
– Evilmaax