下面这一行将导致一个ValueError (Pandas17.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)我知道最后一行的错误。
发布于 2016-09-01 18:14:12
如果您有这样的错误,首先检查您的数据包含您认为它能做什么。
我愚蠢地把一些Series对象添加到一个应该包含int的列中!
发布于 2016-09-01 16:45:35
使用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 NaNhttps://stackoverflow.com/questions/39276650
复制相似问题