小编tac*_*pdt的帖子

使用 .loc 和 OR 运算符返回 ValueError

我试图在两列中的任意一列中搜索特定值,当找到目标值时,将第三列中的数字从正数更改为负数或从负数更改为正数。

te1 = df.loc[df['Transaction Event'] == 'Exercise']
te2 = df.loc[df['Transaction Event'] == 'Assignment']
te3 = df.loc[df['Transaction Event'] == 'Expiration']
an1 = df.loc[df['Action'] == 'Delete']
nq = df['Net Quantity']
var1 = df[(df['Transaction Event'] == 'Exercise') | (df['Transaction Event'] == 'Assignment') | (df['Transaction Event'] == 'Expiration') | (df['Action'] == 'Delete')]

df.loc[df[var1], nq] = df.loc[df[var1], nq] * -1
Run Code Online (Sandbox Code Playgroud)

运行此代码会返回以下错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-282-01dbb8066276> in <module>()
      6 var1 = df[(df['Transaction Event'] == 'Exercise') | (df['Transaction Event'] == 'Assignment') | (df['Transaction …
Run Code Online (Sandbox Code Playgroud)

python operators pandas valueerror

5
推荐指数
1
解决办法
6536
查看次数

标签 统计

operators ×1

pandas ×1

python ×1

valueerror ×1