In this post, we will see how to resolve Pandas interpolation to extend data is giving bad results

## Question:

I have a dataset with`'DEN'`

values as a function
of `'Z'`

, which goes to Z = ~425000, but I would like to extend it up to Z = 500000. I attempted to do this by adding a new data point to my pandas column at Z = 500000, and filling in the `NaN`

values with spline and linear interpolation, but neither result gives a good fit. I tried the other interpolation methods, but none worked. This is the output:but it should look something more like this (with some curvature, probably)

How could I get a better fit? Here is my code:

## Best Answer:

The main issue is that your`Z`

value makes a big jump from 434k to 500k. You should use `Z`

as the index of `df`

because the `interpolate`

method is based on the index values.**Method 1 – Linear extrapolation**

You can do it by adding a single new datapoint.

**Method 2 – Polynomial extrapolation**

You need to add more than 1 new datapoint to get a nice visual plot.

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com