0
我正在研究一個程序,它需要從pandas中取得一張表中的行,並將每一行存儲爲一個字段條目,並將其作爲關鍵字其他人使用該密鑰存儲在對象中。它似乎工作正常,並且當它將它們添加到字典中時沒有出現錯誤,但是如果我嘗試使用像SeqDict ['key']這樣的語法調用該字典中的特定項目。classattribute,我得到一個錯誤說'set'對象沒有'classattribute'屬性,我使用了錯誤的語法還是我的代碼有其他錯誤?這是我第一次嘗試編程,所以如果我犯了一個愚蠢的錯誤,代碼是非常低效寫的。錯誤:'set'對象沒有屬性.. - Python3
我的代碼上半年似乎做工精細
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
由於
這解決了我的問題。非常感謝。 :) – Kimmy