• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Pandas interpolation to extend data is giving bad results

Resolved: Pandas interpolation to extend data is giving bad results

0
By Isaac Tonny on 15/03/2023 Issue
Share
Facebook Twitter LinkedIn

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:
enter image description here
but it should look something more like this (with some curvature, probably)
How could I get a better fit? Here is my code: enter image description here

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.
Output:
Linear extrapolation
Method 2 – Polynomial extrapolation
You need to add more than 1 new datapoint to get a nice visual plot.
Output:
Polynomial extrapolation

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

Source: Stackoverflow.com

interpolation pandas python spline
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: PyCharm cannot see my newly compiled .pyc see on import

27/03/2023

Resolved: I am facing ERR_HTTP2_PROTOCOL_ERROR on my website

27/03/2023

Resolved: TypeScript does not recognize properties when instantiating interface array

27/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.