[英]How to fix this error when take data in Python
The problem here that when I put in user='U3' and debugging I see history1[:, 1][i1][j1] and transactions1[:, 0][m] have the same value.这里的问题是,当我输入 user='U3' 并进行调试时,我看到history1[:, 1][i1][j1]和transactions1[:, 0][m]具有相同的值。 That is ['T500'] but the expression return false (also ['T600']) and when they are have value ['T1000'], they return true.
那是 ['T500'] 但表达式返回 false(也是 ['T600'])并且当它们具有值 ['T1000'] 时,它们返回 true。 And the last output is ['I1', 'I3', 'I2'] instead of ['I1', 'I3', 'I2', 'I3', 'I1', 'I3', 'I2'].
最后的 output 是 ['I1', 'I3', 'I2'] 而不是 ['I1', 'I3', 'I2', 'I3', 'I1', 'I3', 'I2']。 Please give me some advice to fix this.
请给我一些建议来解决这个问题。
Thank for support感谢支持
def createMatrix(user, transactions1, history1):
temp = []
for i1 in range(len(history1[:, 0])):
if history1[:, 0][i1] == user:
for j1 in range(len(history1[:, 1][i1])):
for m in range(len(transactions1[:, 0])):
if history1[:, 1][i1][j1] == transactions1[:, 0][m]: #<------ Problem here
for item in transactions1[:, 1][m]:
temp.append(item)
listNew = dict(zip(*np.unique(temp, return_counts=True)))
return temp
Argument: transactions1参数:transactions1
[[array(['T100'], dtype='<U4') array(['I1', 'I2', 'I5'], dtype='<U2')]
[array(['T200'], dtype='<U4') array(['I2', 'I4'], dtype='<U2')]
[array(['T300'], dtype='<U4') array(['I2', 'I3'], dtype='<U2')]
[array(['T400'], dtype='<U4') array(['I1', 'I2', 'I4'], dtype='<U2')]
[array(['T500'], dtype='<U4') array(['I1', 'I3'], dtype='<U2')]
[array(['T600'], dtype='<U4') array(['I2', 'I3'], dtype='<U2')]
[array(['T700'], dtype='<U4') array(['I1', 'I3'], dtype='<U2')]
[array(['T800'], dtype='<U4') array(['I1', 'I2', 'I3', 'I5'], dtype='<U2')]
[array(['T900'], dtype='<U4') array(['I1', 'I2', 'I3'], dtype='<U2')]
[array(['T1000'], dtype='<U5') array(['I1', 'I3', 'I2'], dtype='<U2')]]
Argument: history1参数:history1
[[array(['U1'], dtype='<U2') array(['T100', 'T400'], dtype='<U4')]
[array(['U2'], dtype='<U2') array(['T200', 'T300', 'T700'], dtype='<U4')]
[array(['U3'], dtype='<U2') array(['T500 ', 'T600 ', 'T1000'], dtype='<U5')]
[array(['U4'], dtype='<U2') array(['T800'], dtype='<U4')]
[array(['U5'], dtype='<U2') array(['T900'], dtype='<U4')]]
Your history1
argument has spaces after T500 and T600.您的
history1
参数在 T500 和 T600 之后有空格。
[array(['U3'], dtype='<U2') array(['T500 ', 'T600 ', 'T1000'], dtype='<U5')]
Your transaction1
argument does not.您的
transaction1
参数没有。
[array(['T500'], dtype='<U4') array(['I1', 'I3'], dtype='<U2')]
[array(['T600'], dtype='<U4') array(['I2', 'I3'], dtype='<U2')]
'T500 '
is not equal to 'T500'
'T500 '
不等于'T500'
Either tidy your data before creating history1
and transactions1
arguments to remove the trailing space, or add a .strip()
on the line with the problem.在创建
history1
和transactions1
arguments 之前整理数据以删除尾随空格,或者在有问题的行上添加.strip()
。
if history1[:, 1][i1][j1].strip() == transactions1[:, 0][m].strip(): #<------ Problem here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.