0

I want to look up values from a table, also when the values are 'in between' the indices.

Example: here's a table from which I want to look up values. What is the easiest way, perhaps a standard function, to look up the value corresponding to (-2,-38)? It seems to me this is quite a common job to do, so I would expect something like table.lookup(-2,38) to exist. Perhaps I don't know the correct search terms but I can't seem to find it.

Example code:

import pandas as pd

d = {-7: [3.6,2.6,2.25,2], 
     0: [4.3,2.8,2.5,2.2], 
     5: [4.8,3.1,2.7,2.4],
     10: [5.5,3.5,3,2.6],
     15: [6.5,4,3.4,2.8]}
table = pd.DataFrame(data=d,index=[35,55,65,75])

table
Out[4]: 
      -7    0    5   10   15
35  3.60  4.3  4.8  5.5  6.5
55  2.60  2.8  3.1  3.5  4.0
65  2.25  2.5  2.7  3.0  3.4
75  2.00  2.2  2.4  2.6  2.8

I defined the table using the example code, but can't find a standard function to look up values from the table in a straightforward way.

I've checked out these related questions but find it hard to believe that this is the best way to go: How to get value from Python table that will be interpolate between columns and rows?

Lookup a value in pandas table and if not there then interpolate between values in python

Merp
  • 1
  • 1
  • Is it important to have a pandas DataFrame? It seems like a scipy interpolate function that takes `x` and `y` as arguments might work better. – SNygard Dec 07 '22 at 16:08
  • Performance is somewhat important so I'd rather not import extra heavy libraries, but I'm open to suggestions doing it without pandas! – Merp Dec 07 '22 at 16:44

0 Answers0