0

I am using this script to get the interpolation values from the excel. It is working fine and giving fine results

import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
import numpy as np

def estimateMonthlySales(domainId,categoryId,salesRank):

    df = pd.read_excel('data.xlsx', sheetname='units')
    df = df.set_index('index')

    indexRef = str(domainId)+'_'+str(categoryId)
    startCol = 7

    array_x1 = df.loc[indexRef,:].index
    array_y1 = df.loc[indexRef,:].values

    array_x = []
    for i in range(startCol,len(array_x1)):
        array_x.append(int(array_x1[i]))

    array_y = []
    for i in range(startCol,len(array_y1)):
        try:
            j = int(array_y1[i])
        except:
            pass
        array_y.append(j)

    #print(array_x)
    #print(array_y)

    return(int(np.interp(salesRank, array_x, array_y)*0.98))


print(estimateMonthlySales(2,468292,600))

I am using numpy interp function. But i want to write my own interpolate function to get the similar results for my dataset as provided by numpy interpolation functoin. How can i write my own interpolation function without use of numpy and pandas.?

I am using Python 3.6.

Ahsan Mukhtar
  • 629
  • 10
  • 31
  • Does this question/answer does not help you? https://stackoverflow.com/questions/7343697/linear-interpolation-python – Guto Aug 25 '17 at 13:12
  • The real question is why you want to _not_ use numpy, and will you get rid of the whole deal of pandas manipulations too? Wanting to leave numpy and keeping pandas is...surprising. – Andras Deak -- Слава Україні Aug 25 '17 at 13:26
  • I always have to install these two libraries and on my server i don't want to install these extra libraries. That is why i want my own interpolation. – Ahsan Mukhtar Aug 25 '17 at 17:03
  • @Guto I tried to see that thread but it could not help me in any way. – Ahsan Mukhtar Aug 25 '17 at 17:04
  • Then you should update your question with what you tried as interpolation code and what went wrong. The ABC of interpolation(ideas and even bit of code) are there. – Guto Aug 25 '17 at 19:44

0 Answers0