ENH: fillna enhancement with method='nearest' #61124
Labels
Enhancement
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Needs Info
Clarification about behavior needed to assess issue
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
This should be a simple follow-up to #9471, enabling support for alignment with method='nearest'.
Since fillna internally uses interpolate, which already supports method='nearest', this might work right away, though it will require extensive testing.
Feature Description
The new feature could be implemented by extending the current alignment functionality in Pandas to support
method='nearest'
. This would allow the user to align two Series or DataFrames by their indices, using the nearest available value when exact matches are not found. Here's a basic idea of how it could be implemented in pseudocode:This functionality could be added as a method to the existing
pandas.DataFrame
andpandas.Series
objects, integrating smoothly into the current API.Alternative Solutions
An alternative solution would be to use the existing
interpolate
function withmethod='nearest'
, which can be applied to the DataFrame or Series before performing the alignment. Additionally, third-party libraries likefuzzywuzzy
orscipy.spatial
could be used for more complex nearest matching.However, native support within Pandas would likely be more efficient and user-friendly.
Additional Context
The text was updated successfully, but these errors were encountered: