0

I have a pandas data frame where I know the start value is the same for all columns and the end value is 90% and 80% of the 100% end value. I need to interpolate between the starting and end values and follow the trend of the 100% value (which is not linear). On a side note: I attempted a linear interpolation between the start and end but that wouldn't work, it returned the same exact dataframe, no NaNs were filled.

                 100%   90%      80%
Date                                
2017-01-01   6.000000     6        6
2017-02-01   6.000000   NaN      NaN
2017-03-01   6.000000   NaN      NaN
2017-04-01   6.000000   NaN      NaN
              ...   ...      ...
2027-08-01  24.666667   NaN      NaN
2027-09-01  24.666667   NaN      NaN
2027-10-01  24.666667   NaN      NaN
2027-11-01  24.666667   NaN      NaN
2027-12-01  24.666667  22.2  19.7333

Solution: My problem was that the data types were objects instead of floats. After converting to floats and setting the 100% as the index I used the following to achieve the desired result:

df = df.interpolate(method='piecewise_polynomial')
red79phoenix
  • 91
  • 3
  • 14
  • I attempted to set the 100% column as the index and interpolate using the polynomial method, but I received the error: TypeError: Cannot interpolate with all NaNs. – red79phoenix Apr 18 '18 at 19:53
  • I found the following: https://stackoverflow.com/questions/34934511/cannot-interpolate-dataframe-even-if-most-of-the-data-is-filled?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa It appears the problem is I have object data types. – red79phoenix Apr 18 '18 at 19:54
  • Have you tried https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.interpolate.html? – TYZ Apr 18 '18 at 19:55
  • 1
    Yeah that's what I tried, turned out my problem was my datatypes were objects instead of floats. what ended up doing the trick was: `df = df.interpolate(method='piecewise_polynomial')` – red79phoenix Apr 18 '18 at 20:18

0 Answers0