TypeError:“值”对象不支持项目分配

时间:2019-04-15 16:09:15

标签: python orange

感谢您的帮助。

我正在使用Orange3(并喜欢它)...我正在聚集大量数据并对其进行处理以进行规范化,格式化和逻辑分析。

我正在使用python处理字段中的数据。

这是一个代码片段:

new_data = in_data.copy()
        for d in new_data:
        for f in d.domain.attributes:
            #print(f)
            if f.name == "Phone":
                counter+=1

                inan = np.isnan(d["Phone"])
                print("NaN Check: " + str(inan))

                fph = str(phone_format(d["Phone"].value))

                print(str(counter) + ": " + fph)
                d[f]["Phone"]=str(fph)

TypeError:“值”对象不支持项目分配

这是令人反感的代码行: d [f] [“电话”] = str(fph)

有人会建议我正确吗?和pythonic(如果可能)在迭代调查期间更新特定字段的方法?

谢谢!

@objectAntics

1 个答案:

答案 0 :(得分:0)

Credit goes to @MarkoToplak

If you want to modify values for Orange.data.Table, you will have to set the correct value in your new_data.X, which is 2D numpy table of floats. It can not contain strings. Strings in Orange.data.Table can only be stored as meta attributes. – Marko Toplak 8 hours ago <

@MarkoToplak you were spot on... I had to modify the inputs to be meta/text and reload the file which made assignment possible. THANK YOU! – objectAntics just now Edit Delete

new_data[counter]["Phone"] = fph