python - 类型错误:scipy.interpolate.interp1d 中的“str”和“float”实例之间不支持“<”
问题描述
尝试使用 interp1d 进行插值时出现此错误
usecols = [i for i in range(0,3)]
VLE_data = pd.read_csv('VLE data.txt',delimiter = ' ',header=1,usecols=usecols)
VLE_data = VLE_data.set_index('methyl')
VLE_data = VLE_data.drop('methyl',axis=0)
VLE_data = VLE_data.reset_index()
T_data = VLE_data.loc[:,'methyl']
T_data1 = VLE_data.loc[0:19,'methyl']
T_data2 = VLE_data.loc[20:37,'methyl']
T_data3 = VLE_data.loc[38:,'methyl']
x_data = VLE_data.loc[:,'acetate']
x_data1 = VLE_data.loc[0:19,'acetate']
x_data2 = VLE_data.loc[20:37,'acetate']
x_data3 = VLE_data.loc[38:,'acetate']
y_data = VLE_data.loc[:,'(1)']
y_data1 = VLE_data.loc[0:19,'(1)']
y_data2 = VLE_data.loc[20:37,'(1)']
y_data3 = VLE_data.loc[38:,'(1)']
VLE_Pdata = pd.read_csv('VLE data.txt',delimiter = ' ')
P_data = VLE_Pdata.loc['methyl','\u03B31']
xnew = np.linspace(0,1,10)
ynew = np.linspace(0,1,10)
funP1x = interp1d(x_data1,T_data1,kind='linear')
funP3x = interp1d(x_data2,T_data2,kind='linear')
funP7x = interp1d(x_data3,T_data3,kind='linear')
funP1y = interp1d(y_data1,T_data1,kind='linear')
funP3y = interp1d(y_data2,T_data2,kind='linear')
funP7y = interp1d(y_data3,T_data3,kind='linear')
T1new = funP1x(xnew)
结果我得到了这个错误:
Traceback (most recent call last):
File "C:\Users\VLE.py", line 46, in <module>
T1new = funP1x(xnew)
File "C:\Anaconda\lib\site-packages\scipy\interpolate\polyint.py", line 78, in __call__
y = self._evaluate(x)
File "C:\Anaconda\lib\site-packages\scipy\interpolate\interpolate.py", line 675, in _evaluate
y_new = self._call(self, x_new)
File "C:\Anaconda\lib\site-packages\scipy\interpolate\interpolate.py", line 605, in _call_linear
x_new_indices = searchsorted(self.x, x_new)
File "<__array_function__ internals>", line 5, in searchsorted
File "C:\Anaconda\lib\site-packages\numpy\core\fromnumeric.py", line 1348, in searchsorted
return _wrapfunc(a, 'searchsorted', v, side=side, sorter=sorter)
File "C:\Anaconda\lib\site-packages\numpy\core\fromnumeric.py", line 67, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
File "C:\Anaconda\lib\site-packages\numpy\core\fromnumeric.py", line 44, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
TypeError: '<' not supported between instances of 'str' and 'float'
是什么导致这个错误?
解决方案
推荐阅读
- mysql - 选择显示较少行和不同的查询,计数显示更多行
- flutter - 没有文字的底部导航栏
- websocket - 使用 websocket 为基于 ruby-graphql 的 rails 应用程序选择配置
- scala - 为什么 Files.write 不能使用 Array[Byte]()?
- ruby - 我想提取并列出从每个 cron 作业旁边的服务器打印的 cron 作业
- javascript - 在 React SPA 中保护 API 密钥
- java - Spring boot - 在其他任何事情之前初始化数据源
- opencv - 是否可以透视将椭圆转换为圆形?
- c# - 如何上传 Excel 文件以及附加文件名的新 GUID?
- google-cloud-platform - 谷歌云云 NAT 网关