0

I have a pandas table of wind speed values ("WS") and I want to look up the corresponding power values in a lookup table ("PC"). If the exact value doesn't exist, then I want it to interpolate between the values in the lookup table. Is this simple and possible to do? I was able to accomplish this in excel so I feel like there should be a way to do this here in python.

Data in text:

print (WS)
0    6.869516
1    6.366496
2    5.863476
3    5.360457
4    5.073017
5    4.569997
6    3.995117
7    3.563957
8    3.204657
9    3.132797
dtype: float64

print (PC)
      WS  Power [kWh]
0   0.0            0
1   0.5            0
2   1.0            0
3   1.5            0
4   2.0            0
5   2.5            0
6   3.0            0
7   3.5           55
8   4.0          128
9   4.5          211
10  5.0          310
11  5.5          431
12  6.0          567
13  6.5          727
14  7.0          910
15  7.5         1119
16  8.0         1356

What is the best way and simplest way to accomplish this? For example, for WS[0] which is 6.869516, this value falls between 6.5 and 7 WS in the look up table this would give a power value between 727 and 910 kwh but probably closer to the 910 value. I would want the code to interpolate between the values and split out the interpolated power value for each WS in the "WS" pandas table.

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
HM14
  • 689
  • 1
  • 10
  • 30
  • 3
    It would be great if you could include [`re-producible dataset`](https://stackoverflow.com/q/20109391/4985099) with input & expected output. – sushanth Oct 04 '22 at 05:09

1 Answers1

1

Use numpy.interp because values of PC['WS'] are increasing:

df = WS.to_frame('WS')
df['new'] = np.interp(WS, PC['WS'], PC['Power [kWh]'])
print (df)
         WS         new
0  6.869516  862.242856
1  6.366496  684.278720
2  5.863476  529.865472
3  5.360457  397.230594
4  5.073017  327.670114
5  4.569997  224.859406
6  3.995117  127.287082
7  3.563957   64.337722
8  3.204657   22.512270
9  3.132797   14.607670
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252