简体   繁体   English

Python取数据报错怎么解决

[英]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.在创建history1transactions1 arguments 之前整理数据以删除尾随空格,或者在有问题的行上添加.strip()

if history1[:, 1][i1][j1].strip() == transactions1[:, 0][m].strip(): #<------ Problem here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从服务器获取数据时如何修复python中的unicode错误 - How fix unicode error in python when getting data from server 如何在python中安装恼人时修复错误 - How to fix error when installing annoy in python 尝试连接到 API 时如何修复 Python 中的“找不到数据”错误 - How to fix "Data can not be found' error in Python when trying to connect to API 当我尝试在python中合并两个数据帧时,如何修复“内存错误” - How to fix the 'Memory Error' when i am trying to merge two data frames in python 使用python psycopg2保存二进制数据时如何修复“无法适应错误” - How to fix “can't adapt error” when saving binary data using python psycopg2 如何修复 python:当我已经安装 python 时找不到错误 - How to fix python: not found error when I already installed python 数据增强 TensorFlow 训练数据时如何修复错误? - How to fix the error when data augmenting TensorFlow training data? 如何在执行python切片和索引时修复值错误? - How to fix value error when doing python slicing and indexing? 在python上解析网站时如何修复错误403? - How to fix Error 403 when parsing a site on python? 在 Python 中导入搅拌机模块时如何修复错误 - How to fix error when importing the blender module in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM