我有一个带有转速和效率值的数据框.RPM曲线值不是均匀分布的,并且RPM值是不规则间隔.如何才能使RPM值以规则的间隔出现?以下是我的数据和Python代码:

dict ={'rpm': [363, 362, 361, 360, 359, 358, 357, 356, 357, 354, 357, 356, 354, 351, 350, 349, 348, 347, 346, 345, 344, 342, 340, 339, 338, 337, 334, 332, 330, 329, 327, 325, 324, 321, 319, 317, 316, 313, 310, 308, 299, 288, 275, 265, 256, 247, 239, 230, 220, 209, 207, 200, 191, 182, 172, 164, 156, 148, 141, 135, 128, 121, 111, 110, 91, 98, 87, 74, 79, 76, 68, 50, 51, 50, 51, 41, 24, 0], 'eff': [30.0, 44.7, 55.0, 65.5, 71.85, 75.8, 79.05, 82.25, 81.0, 87.7, 85.8, 87.2, 87.0, 89.0, 88.2, 88.4, 89.0, 90.8, 89.6, 89.3, 89.6, 89.56666666666668, 89.8, 87.9, 89.2, 90.7, 88.0, 88.3, 88.6, 89.4, 87.2, 86.7, 85.6, 85.4, 85.3, 85.4, 85.1, 86.0, 84.5, 83.8, 82.9, 81.8, 80.7, 79.6, 78.8, 77.8, 77.0, 75.9, 74.7, 73.5, 73.2, 72.2, 70.6, 69.1, 67.4, 65.9, 64.2, 62.4, 60.7, 59.1, 57.2, 55.5, 52.0, 51.8, 44.6, 48.1, 43.8, 39.0, 41.4, 40.3, 36.8, 28.4, 29.1, 28.1, 28.9, 23.7, 1.6, 0.0]}
df = pd.DataFrame(dict)

enter image description here in rpm columns the difference between every two adjacent values is sometime 1 sometimes 0 sometimes more than 1 how to make them equally distributed so that difference between any two adjacent values is 2 something the rpm values has to be 363,360,357,354,............,9,6,3 and I want to get to know for every rpm value what is the efficiency how to do it I used interpolation but the curve points are not equally distributed kindly help me through it thanks in advance

推荐答案

你说得对,我们要做的就是插补:

import scipy.interpolate
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

f = scipy.interpolate.interp1d(df["rpm"],df["eff"])
rpm_interp=np.linspace(0,363,1000)
#this gives you 1000 equally spaced points between 0 and 363
#you can get your values spaced out by 3 by replacing 1000 with 363//3 + 1
eff_interp=f(rpm_interp)
plt.plot(rpm_interp,eff_interp)

Which gives you this when you plot efficiency as a function of RPM : enter image description here

Python相关问答推荐

Pydantic 2.7.0模型接受字符串日期时间或无

2维数组9x9,不使用numpy.数组(MutableSequence的子类)

Pandas 在最近的日期合并,考虑到破产

Python上的Instagram API:缺少client_id参数"

需要计算60,000个坐标之间的距离

如何避免Chained when/then分配中的Mypy不兼容类型警告?

Excel图表-使用openpyxl更改水平轴与Y轴相交的位置(Python)

大小为M的第N位_计数(或人口计数)的公式

为什么sys.exit()不能与subproccess.run()或subprocess.call()一起使用

OR—Tools中CP—SAT求解器的IntVar设置值

梯度下降:简化要素集的运行时间比原始要素集长

在极性中创建条件累积和

Django RawSQL注释字段

Pandas Data Wrangling/Dataframe Assignment

* 动态地 * 修饰Python中的递归函数

freq = inject在pandas中做了什么?''它与freq = D有什么不同?''

为用户输入的整数查找根/幂整数对的Python练习

获取git修订版中每个文件的最后修改时间的最有效方法是什么?

Python OPCUA,modbus通信代码运行3小时后出现RuntimeError

无法使用请求模块从网页上抓取一些产品的名称