【发布时间】:2016-07-09 16:28:49
【问题描述】:
这个问题是我关于linear interpolation between two data points的问题的后续
我从中构建了以下功能:
def inter(colA, colB):
s = pd.Series([colA, np.nan, colB], index= [95, 100, 102.5])
s = s.interpolate(method='index')
return s.iloc[1]
现在我有一个如下所示的数据框:
on95 on102.5 on105
Index
1 5 17 20
2 7 15 25
3 6 16 23
我想创建一个新列df['new'],它使用函数inter,输入为on95 和on102.5
我试过这样:
df['new'] = inter(df['on95'],df['on102.5'])
但这导致了 NaN。
我也尝试了apply(inter),但没有找到一种方法让它在没有错误消息的情况下工作。
任何提示我如何解决这个问题?
【问题讨论】:
标签: python function pandas vectorization