Pandas.DataFrame interpolate() with method='linear' and 'nearest' returns inconsistent results for trailing NaN
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I was exploring pandas.DataFrame.interpolate() with different methods, linear vs. nearest , and I found different outputs from the two methods when there is missing data at the trailing. For example: import pandas as pd # version: '0.16.2' or '0.20.3' >>> a = pd.DataFrame({'col1': [np.nan, 1, np.nan, 3, np.nan, 5, np.nan]}) Out[1]: col1 0 NaN 1 1.0 2 NaN 3 3.0 4 NaN 5 5.0 6 NaN >>> a.interpolate(method='linear') Out[2]: col1 0 NaN 1 1.0 2 2.0 3 3.0 4 4.0 5 5.0 6 5.0 >>> a.interpolate(method='nearest') Out[3]: col1 0 NaN 1 1.0 2 1.0 3 3.0 4 3