Linear interpolation is a method for filling in missing values in a sequence by drawing a straight line between the nearest known values on each side. It is one of the most common imputation techniques for time series data, preserving the local trend between observed points.
Given a Python list of numbers where some entries are None (missing), fill in the missing values using linear interpolation between the nearest known neighbors. Return a new Python list (do not use NumPy).
For each gap of consecutive None values between known values at positions left and right:
value[j]=vleft+right−leftj−left⋅(vright−vleft)where j is the position of the missing value, and v_left, v_right are the known values bounding the gap.
Return a list of the same length with no None values.
Input: values = [1, None, 3]
Output: [1, 2.0, 3]
Explanation: The missing midpoint is halfway between 1 and 3.
Input: values = [0, None, None, 6]
Output: [0, 2.0, 4.0, 6]
When a gap begins, locate the known value immediately before it and the next known value after it.
Fill each gap position by its fractional distance between the two endpoints.
Sign in to take notes on this problem
Accepts: array
Linear interpolation is a method for filling in missing values in a sequence by drawing a straight line between the nearest known values on each side. It is one of the most common imputation techniques for time series data, preserving the local trend between observed points.
Given a Python list of numbers where some entries are None (missing), fill in the missing values using linear interpolation between the nearest known neighbors. Return a new Python list (do not use NumPy).
For each gap of consecutive None values between known values at positions left and right:
value[j]=vleft+right−leftj−left⋅(vright−vleft)where j is the position of the missing value, and v_left, v_right are the known values bounding the gap.
Return a list of the same length with no None values.
Input: values = [1, None, 3]
Output: [1, 2.0, 3]
Explanation: The missing midpoint is halfway between 1 and 3.
Input: values = [0, None, None, 6]
Output: [0, 2.0, 4.0, 6]
When a gap begins, locate the known value immediately before it and the next known value after it.
Fill each gap position by its fractional distance between the two endpoints.
Sign in to take notes on this problem
Accepts: array