For a DataFrame with sorted float index and columns, calculate the value using linear interpolation based on the DataFrame values

I am working with a DataFrame with sorted index and column float values:

      9    15
5.0   2     9
8.0   3     1

I would like to use this DataFrame as the basis for calculating the value for a given combination of index and column, for example (6.0, 12), where the values ​​from the DataFrame will be taken for interpolation:

        9    12    15
5.0     2     -     9
6.0  (ci)  (ri)  (ci)
8.0     3     -     1

Where the values ​​(ri) are calculated by interpolating the values ​​in the row, and the values ​​(ci) are interpolated using the values ​​in the column, and the average value is the value we want to get. The calculation procedure is to first calculate all the values ​​in the row using interpolation for the corresponding columns, and then interpolate the final value in the row.

:

         9    12    15
5.0      2     -     9
6.0   2.33  4.33  6.33
8.0      3     -     1

, , 4.33.

, DataFrame , , , (5.0, 9) 2.

+4
1

, numpy.interp

l=[np.interp(6,df.index, df[x]) for x in df.columns]
np.interp(12,df.columns.astype(int), l)
Out[1140]: 4.333333333333334
0

Source: https://habr.com/ru/post/1693916/


All Articles