当我使用 eval 时如何使用 df.appen

How can use df.appen when I use eval

j=88.87

我想用 eval 做这样的事情:

data_88_87=data_88_87.append(data[data['norm']==88.87])

但是:

eval('data_'+str(j).replace('.','_'))=eval('data_'+str(j).replace('.','_')).append(data[data['norm']==j])



File "<ipython-input-110-a69e45d994b1>", line 5
    eval('data_'+str(j).replace('.','_'))=eval('data_'+str(j).replace('.','_')).append(data[data['norm']==j])
    ^
SyntaxError: can't assign to function call
eval('data_'+str(c).replace('.','_')+'='+('data_'+str(c).replace('.','_')).append(data[data['norm']==j]))


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-121-64d2b5d27c76> in <module>()
----> 1 eval('data_'+str(c).replace('.','_')+'='+('data_'+str(c).replace('.','_')).append(data[data['norm']==2.98]))

AttributeError: 'str' object has no attribute 'append'

如何在使用 eval 时使用 df.appen?

您可以按如下方式使用:

j = 88.87
tempVar = "data_"+str(j).replace('.','_')
globals()[tempVar] = eval(globals()[tempVar]).append(data[data['norm']==88.87])

上面的代码会给你下面的输出:

data_88_87=data_88_87.append(data[data['norm']==88.87])