我有一个数据框,其中包含森林I(第一列)和设施j(顶行)之间的距离值(km):
Df1=
Forest,Bell Bay,Surrey Hills,Smithton,Hobart
Coupe1,158,194,10,49
Coupe2,156,169,71,84
Coupe3,10,186,101,163
Coupe4,47,194,134,139
Coupe5,144,161,135,56
Coupe6,27,127,134,36
Coupe7,114,104,143,113
Coupe8,71,170,190,140
Coupe9,194,154,173,128
Coupe10,46,194,92,36
我有最大距离参数Dmax=100公里
我用二进制值创建了一个数据帧。如果森林和设施之间的距离为<;=Dmax然后为1,否则为0。数据框如下所示:
Df2=
Forest,Bell Bay,Surrey Hills,Smithton,Hobart
Coupe1,0,0,1,1
Coupe2,0,0,1,1
Coupe3,1,0,0,0
Coupe4,1,0,0,0
Coupe5,0,0,0,1
Coupe6,1,0,0,1
Coupe7,0,0,0,0
Coupe8,1,0,0,0
Coupe9,0,0,0,0
Coupe10,1,0,1,1
我有另一个数据框,它具有如下所示的供应浮点值:(注意,林或索引是相同的)
Df3=
Forest,Supply
Coupe1,6000
Coupe2,1000
Coupe3,9000
Coupe4,3000
Coupe5,3000
Coupe6,4000
Coupe7,9000
Coupe8,7000
Coupe9,5000
Coupe10,3000
我想用二进制参数创建另一个数据帧(或前一个数据帧['Binary']中的额外列),如果林I在任何设施j的Dmax范围内,则为1。数据框应如下所示:
Df3=
Forest,Supply, Binary
Coupe1,6000,1
Coupe2,1000,1
Coupe3,9000,1
Coupe4,3000,1
Coupe5,3000,1
Coupe6,4000,1
Coupe7,9000,0
Coupe8,7000,1
Coupe9,5000,0
Coupe10,3000,1
请注意,对于Coupe 7和9,二进制值为0,因为根据第一个数据帧,这两个森林距离贝尔湾、萨里山、史密斯顿和霍巴特设施都超过100公里。 最好的方法是什么
如果行林中有1,则Df3['Binary']=1,否则为0
例如
for i in Df2
if Coupe1,0,0,1,1
then 1 in Df3['Binary']
if Couple7, 0,0,0,0
then 0 in Df3['Binary']
由于
Df2
和Df3
具有相同的行序列,因此可以执行以下操作:在这种情况下,行序列在
Df2
&Df3
,您可以执行以下操作:相关问题 更多 >
编程相关推荐