繁体   English   中英

错误:“设置”对象没有属性。-Python3

[英]Error: 'set' object has no attribute.. - Python3

我正在开发一个程序,该程序需要从熊猫中提取表中的行,并将每行作为字典条目存储,其中一列作为键,而其他存储在具有该键的对象中。 似乎可以正常工作,并且在将其添加到字典中时没有出现任何错误,但是,如果我尝试使用SeqDict ['key']。classattribute这样的语法从该字典中调用特定项目,则会出现错误说“'set'对象没有属性'classattribute'。我使用的是错误的语法还是我的代码有其他问题?这是我第一次尝试编程,对不起,如果我犯了一个愚蠢的错误或我的错,代码编写效率很低。

我的代码的前半部分似乎工作正常

import os
import pandas as pd

print("Please move your CSV to the desktop before continuing.")
csvfilename = input("Enter the name of your CSV file: ")
desktopfilepath = os.path.expanduser("~/Desktop/")
csvfilepath = desktopfilepath + csvfilename

seqtable = (pd.read_csv(csvfilepath, 
                    dtype=str, 
                    header=0, 
                    usecols=["Well", "Core Sample ID", "Sample ID", "Exon"]))

newseqtable = pd.DataFrame.dropna(seqtable)
print(newseqtable)

y = len(newseqtable.index)
print(y, "files to rename.") 

我假设这是我做错事的地方

class SeqID:
    def __init__(self,well,sequence,exon):
        self.well = well
        self.sequence = sequence
        self.exon = exon
SeqDict = {}

x = 0
for x in range(y):
    ID = newseqtable.iat[x,1]
    well = newseqtable.iat[x,0]
    sequence = newseqtable.iat[x,2]
    exon = newseqtable.iat[x,3]
#    print(ID + "," + well + "," + sequence + "," + exon + ".") #This works fine when I choose to run it
    SeqDict[ID] = {SeqID(well,sequence,exon)}
SeqDict  #This prints the dictionary keys I would expect

SeqDict['key'].well  # This returns the error when I insert a key

谢谢

这行:

 SeqDict[ID] = {SeqID(well,sequence,exon)} 

创建一个1套。 您可能的意思是:

SeqDict[ID] = SeqID(well,sequence,exon)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM