我有一个有三列的数据框: 深度、页岩体积和密度。你知道吗
我需要做的是根据页岩体积和密度计算孔隙度。因此,当页岩体积大于0.7时,我将某些参数用于孔隙度计算,当页岩体积小于0.2时,我将使用其他参数。你知道吗
例如,如果页岩体积为<;0.2:
porosity=density*2.3
如果页岩体积大于0.7:
porosity=density*1.7
这是数据帧部分的示例,如果有:
depth density VSH
5517 2.126 0.8347083
5517.5 2.123 0.8310949
5518 2.124 0.8012414
5518.5 2.121 0.7838615
5519 2.116 0.7674243
5519.5 2.127 0.8405414
这就是我要做的一段代码。我希望它处于for循环中,因为它将用于将来的目的:
for index, row in data.iterrows():
if data.loc[index, 'VSH']<0.2:
data.loc[index,'porosity']=(data['density']*2.3)
elif data.loc[index, 'VSH'] > 0.7:
data.loc[index,'porosity']=(data['density']*1.7)
我得到的错误如下,如果您能为我提供帮助就太好了:
TypeError: '<' not supported between instances of 'str' and 'float'
这里
iterrows
是一个不好的选择,因为速度慢并且存在矢量化的解决方案,请检查Does pandas iterrows have performance issues?所以使用^{} :
更好的定义是,在
0.2 and 0.7
之间发生什么-例如,默认参数中data['density']
列的返回值:相关问题 更多 >
编程相关推荐