问题描述
我有十年的天气数据,包括每天的最高温度(Tmax
,最低温度(Tmin
),降雨量和太阳辐射(Ra
)。
首先,我想使用以下公式计算每天的蒸散量(eto):
eto=0.0023*(((Tmax+Tmin)/2)+17.8)*sqrt(Tmax-Tmin)*Ra
然后,计算所有参数(Tmax,Tmin,Rainfall,Ra and eto)
的每月和每年平均值,并以Excel格式打印。
我写了一些部分。你能帮我完成吗?我认为可能需要一个 loop 。
import numpy as np
import pandas as pd
import math as mh
# load the weather data file
data_file = pd.read_excel(r'weather data.xlsx',sheet_name='city_1')
# defining time
year = data_file['Year']
month = data_file['month']
day = data_file['day']
# defining weather parameters
Tmax = data_file.loc[:,'Tmax']
Tmin = data_file.loc[:,'Tmin']
Rainfall = data_file.loc[:,'Rainfall']
Ra = data_file.loc[:,'Ra']
# adjusting time to start at zero
year = year-year[0]
month=month-month[0]
day=day-day[0]
#calculation process for estimation of evapotranspiration
ET0=(0.0023*(((Tmax+Tmin)/2)+17.8)*(mh.sqrt(Tmax-Tmin))*Ra
解决方法
看起来您每天只有一个数据行(记录)。
由于该行中已经有Tmax,Tmin,降雨和星期日,因此您可以使用以下计算添加一个净ET0行:
data_file['ET0'] = data_file.apply(lambda x: 0.0023*(((x.Tmax+x.Tmin)/2)+17.8)*(mh.sqrt(x.Tmax-x.Tmin))*x.Ra,axis=0)