In this post, we will see how to resolve fill values ONLY BETWEEN rows in a pandas DataFrame
Question:
I am working on a project with some pricing data for second hand cars, due to the nature of the data there are gaps in the dataframe I am working with.I need to fill the gaps in the columns, but only if they are BETWEEN two values (i.e. there are values both above the
Nan
).Here is a simplified example of what I am working with:
.ffil()
.bfill()
and .fillna()
but these seem to be uniquely forward or backwards filling. I need to fill forwards but only for blanks between two values.The expected outcome is
Best Answer:
You can useinterpolate
with right parameters:If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com