Here is a sample of a larger data set:
df_old = pd.DataFrame({'code': ['fea-1','fea-132','fea-223','fea-394','fea-595','fea-130','fea-495'],
'forecastWind_low':[20,15,0,45,45,25,45],
'forecastWind_high':['NaN' ,30,'NaN',55,65,35,'NaN'],
'obs_windSpeed':[20,11,3,65,55,'NaN',55]})
I have forecast windspeeds which I need to compare to observations... Ultimately I need to find the closest forecast speed (low or high) to the observation wind speed value to get an output as below:
df_new = pd.DataFrame({'code': ['fea-1','fea-132','fea-223','fea-394','fea-595','fea-130','fea-495'],
'forecastWind_low':[20,15,0,45,45,25,45],
'forecastWind_high':['NaN' ,30,'NaN',55,65,35,'NaN'],
'obs_windSpeed':[20,11,3,65,55,'NaN',55],
'nearest_forecast_windSpeed':[20,15,0,55,45,'NaN',45]})