0

Fellows, so I am trying to come up with code that fill the nan values with value between the previously an next value.

-

It is a plus if we can come up with a value that keeps the natural log of the curve.

data:

df = pd.DataFrame("Weeks": [1,2,3,4,5,6,7,8,10],
    "Values": [100,80,nan,nan,nan,69,68,nan,50,40] )

Desired output:

Weeks         Values
1              100
2              80
3               nan ? =(should give a value in between)
4               nan ?
5               nan ?
6              69
7              68

# and so on...

Would be even better output (extra):

- it uses Logarithmic interpolation to fill the blanks

- it keeps the natural log of the curve

math:

(Upper Boundary-Lower Boundary) * (Ln(position of blank interval)/ln(total size of the blank intervals)) / 1 ) + Lower Boundary

so like following the example above:

so like Ln(2)/ln(3) for the first one if there's 13 blanks in a row  then the next would be ln(3)/ln(13), 13 is the size of how many blanks there are +2 so if theres 1 blank by it self
its ln(2)/ln(3)

Feel welcome to come up with your own formula, the goal is come up replace numbers that will follow the natural log of the curve. But just number that fits between the curve is a valid answer too.

Peter
  • 544
  • 5
  • 20
  • 1
    These are probably your best bets: https://stackoverflow.com/questions/29346292/logarithmic-interpolation-in-python – jfaccioni Apr 10 '20 at 18:09
  • 1
    Did you try making [pandas.DataFrame.interpolate](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.interpolate.html) work? – wwii Apr 10 '20 at 18:41
  • @wwii nop, let me take a look in the documentation, thank you – Peter Apr 10 '20 at 18:42
  • 1
    related: [How to do exponential and logarithmic curve fitting in Python? I found only polynomial fitting](https://stackoverflow.com/questions/3433486/how-to-do-exponential-and-logarithmic-curve-fitting-in-python-i-found-only-poly) ... Roll your own and replace `nans` using the `'weeks'` values for the independent variable. – wwii Apr 10 '20 at 18:49

1 Answers1

0

This answer the simple interpolation, worked! but still trying to implement much sofisticated answer using natural log.

df['interpolated_value'] = df.Values.interpolate(method='index')

following some good resources sent by @wwii

How to do exponential and logarithmic curve fitting in Python? I found only polynomial fitting

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.interpolate.html

Peter
  • 544
  • 5
  • 20