Python在简单查询中出现错误

Python在简单查询中出现错误,python,pandas,numpy,Python,Pandas,Numpy,下面这行代码会导致ValueError(17.1),我正在试图理解原因 x = (matchdf['ANPR Matched_x'] == 1) ValueError:序列的真值不明确。使用a.empty、a.bool()、a.item()、a.any()或a.all() 我尝试将其用于以下条件赋值: matchdf.loc[x, 'FullMatch'] = 1 但我无法通过上一个问题 我肯定我以前做过几十次这样的事情,我不明白为什么数据帧中的内容很重要,但也许它真的很重要?或者更可能的是

下面这行代码会导致ValueError(17.1),我正在试图理解原因

x = (matchdf['ANPR Matched_x'] == 1)
ValueError:序列的真值不明确。使用a.empty、a.bool()、a.item()、a.any()或a.all()

我尝试将其用于以下条件赋值:

matchdf.loc[x, 'FullMatch'] = 1
但我无法通过上一个问题

我肯定我以前做过几十次这样的事情,我不明白为什么数据帧中的内容很重要,但也许它真的很重要?或者更可能的是,我可能犯了一个我看不见的愚蠢的错误

谢谢你的帮助

编辑:有关更多上下文,请参见前面的一些代码:

inpairs = []
for m in inmatchedpairs:
    # more code
    p = {'Type In': mtype ,'Best In Time': besttime, 'Best G In Time': bestgtime,
         'Reg In': reg, 'ANPR Matched': anprmatch, 'ANPR Match Key': anprmatchkey}
    inpairs.append(p)

outpairs = []
for m in outmatchedpairs:
    # more code
    p = {'Type Out': mtype ,'Best Out Time': besttime, 'Best G Out Time': bestgtime,
         'Reg Out': reg, 'ANPR Matched': anprmatch, 'ANPR Match Key': anprmatchkey}
    outpairs.append(p)

indf = pd.DataFrame(inpairs)
outdf = pd.DataFrame(outpairs)
matchdf = pd.merge(indf, outdf, how='outer', on='ANPR Match Key')
matchdf['FullMatch'] = 0

x = (matchdf['ANPR Matched_x'] == 0)

我在最后一行得到错误。

使用
loc
设置值

matchdf.loc[matchdf['APNR Matched_x'] == 1, 'FullMatch'] = 1
示例

df = pd.DataFrame({'APNR Matched_x': [0, 1, 1, 0], 'Full Match': [False] * 4})

>>> df
   APNR Matched_x Full Match
0               0      False
1               1      False
2               1      False
3               0      False

df.loc[df['APNR Matched_x'] == 1, 'FullMatch'] = 1

>>> df
   APNR Matched_x Full Match  FullMatch
0               0      False        NaN
1               1      False          1
2               1      False          1
3               0      False        NaN

使用
loc
设置值

matchdf.loc[matchdf['APNR Matched_x'] == 1, 'FullMatch'] = 1
示例

df = pd.DataFrame({'APNR Matched_x': [0, 1, 1, 0], 'Full Match': [False] * 4})

>>> df
   APNR Matched_x Full Match
0               0      False
1               1      False
2               1      False
3               0      False

df.loc[df['APNR Matched_x'] == 1, 'FullMatch'] = 1

>>> df
   APNR Matched_x Full Match  FullMatch
0               0      False        NaN
1               1      False          1
2               1      False          1
3               0      False        NaN

如果您有这种错误,首先检查您的数据帧是否包含您认为它的功能


我愚蠢地将一些Series对象添加到其中一个应该包含int的列中

如果您有这种错误,首先检查您的数据帧是否包含您认为它的功能


我愚蠢地将一些Series对象添加到其中一个应该包含int的列中

这应该行得通,你能提供一个例子吗?我已经添加了更多的例子,但似乎无法在其他地方复制它。困惑的这应该行得通,你能提供一个例子吗?我已经添加了更多的例子,但似乎无法在其他地方复制它。困惑的谢谢我想我的问题一定与合并后数据框中的内容有关,或者与某种类型的熊猫bug有关。谢谢。我认为我的问题一定与合并后数据帧中的内容有关,或者与某种类型的熊猫bug有关。