pythonpandasinterpolation

Python Pandas Interpolate nan columns with respect to the column values


I have data in Pandas, where the temperatures are the column headers and the COP values are in the matrix.

If I interpolate using pandas interpolate function I end up with linear interpolate, not weighted to the temperature at the top.

For example, here is my original data: enter image description here

I have added the needed columns and I need to interpolate with respect to the column header version.. If I use the interpol function, the values are interpolated but not with respect to the temperature. See example, incorrect interpolation. enter image description here

Is this possible in Pandas or should I remove it our of a dataframe and rather do it in Scipy?


Solution

  • Pandas is not what you want. The orig.interpolate(axis=1) is your doom.

    By default, pandas.DataFrame.interpolate() assumes the columns are equally spaced when interpolating across columns. Even though you have labels (temperatures), it ignores them. (axis=1) tells it to go column by column, equally spaced, with no care for label.

    I was about to represent SciPy's interp1d as an alternative, but it's deprecated, which I did not know until now. The replacements are in their documentation, which include numpy.interp() and more.