python - 如何在 Python 中进行插值?
问题描述
我想对我的数据帧 df2 中的 Value_B 列进行线性插值。如何以简单的方式使用 python 做到这一点?
df2 = pd.DataFrame(np.array([[1, 2, 10], [2, 5, ''], [3, 8, 30], [4, 2, ''], [5, 5, 50], [6, 8, '']]), columns=['Angle', 'Value_A', 'Value_B'])
df2
Value_B 的结果应该是 10, '20', 30, '40', 50, '60'。
解决方案
熊猫 interpolate()
功能
df2.interpolate(method ='linear', limit_direction ='forward')
您甚至可以向后插值并设置限制
df.interpolate(method ='linear', limit_direction ='backward', limit = 1)
推荐阅读
- c++ - 构造函数初始化指针数据成员的问题
- python - 按降序计算值列表的频率及其相关的值百分比更高
- javascript - 如何使用 array.map 方法从数组数组中返回对象数组?
- android - java.lang.RuntimeException:在错误的 GL 上下文中应用效果!在 android 应用程序中同时在图像上应用过滤器
- c# - C# Selenium 在不同的机器上不一致
- java - @Query 和 DTO 之间的映射 Clob
- c++ - C ++类构造函数中带const和不带const的param有什么区别
- c# - ASP.Net 对象在 OnGet() 方法后设置回 null
- java - Spring Boot无法正常工作并出现一些错误?
- vba - 有没有办法,当声明一个变量来限制它的可能值?