How To Get Value From Python Table That Will Be Interpolate Between Columns And Rows?
I have got table (DataFrame) created in Pandas. It is 2D table with integers as column index and integer as row index (it is
position x and
I know how to get value that is in "cell" of that table using indexes, but I would like to get value "from between" columns and rows that will be linearly interpolated.
Preferably, I would like to do this for large number of x,y that are kept in two tables
Position_x(m x n),
Position_y(m x n) and put results to table
Results(m x n)
Here is example of such procedure in Excel: https://superuser.com/questions/625154/what-is-the-simplest-way-to-interpolate-and-lookup-in-an-x-y-table-in-excel
I've found something that works in 90%, however, it has two disadvantages: 1) index and columns need to be strictly increasing, 2) for a set of n input pairs it plots n x n result array instead of just n results (for example below for 3 pairs of input points I need only 3 resulting values, using that code I will get 9 values as all combination of input points).
Here is what I've found:
import scipy import scipy.interpolate import numpy as np import pandas as pd x=np.array([0,10,25,60,100]) #Index y=np.array([1000,1200,1400,1600]) #Column data=np.array([[60,54,33,0], [50,46,10,0], [42,32,5,0], [30,30,2,0], [10,10,0,0]]) Table_to_Interpolate=pd.DataFrame(data,index=x,columns=y) sp=scipy.interpolate.RectBivariateSpline(x,y,data, kx=1, ky=1, s=0) scipy.interpolate.RectBivariateSpline(x,y,data, kx=1, ky=1, s=0) Input_Xs=12, 44, 69 Input_Ys=1150, 1326, 1416 Results=pd.DataFrame(sp(Input_Xs, Input_Ys), index=Input_Xs, columns=Input_Ys,)
It's not perfect, but it's the best I could find.
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module