Python 属性错误:';unicode';对象没有属性';合并';
这是我的代码:Python 属性错误:';unicode';对象没有属性';合并';,python,user-interface,attributeerror,Python,User Interface,Attributeerror,这是我的代码: class Window(Tk): def __init__(self, parent): Tk.__init__(self, parent) self.parent = parent self.initialize() def initialize(self): self.geometry("600x400+30+30") self.wButton = Button(self,
class Window(Tk):
def __init__(self, parent):
Tk.__init__(self, parent)
self.parent = parent
self.initialize()
def initialize(self):
self.geometry("600x400+30+30")
self.wButton = Button(self, text='Product Price List', command = self.OnButtonClick)
self.wButton.pack()
def OnButtonClick(self):
self.top = Toplevel()
self.top.title("Product Price List")
self.top.geometry("300x300+30+30")
self.top.transient(self)
self.wButton.config(state='disabled')
self.topButton = Button(self.top, text="Import Price list CSV", command = self.OnImport)
self.topButton.pack()
self.topButton = Button(self.top, text="Import Price Adjustment CSV", command = self.OnImport2)
self.topButton.pack()
self.topButton = Button(self.top, text="Import Price Adjustment CSV", command = self.OnImport3)
self.topButton.pack()
self.topButton = Button(self.top, text="Save As", command = self.OnSaveAs)
self.topButton.pack()
self.topButton = Button(self.top, text="CLOSE", command = self.OnChildClose)
self.topButton.pack()
def OnImport(self):
self.a = askopenfilename()
def OnImport2(self):
self.b = askopenfilename()
self.c = self.a.merge(self.b, how='left', left_on='Dynamic_spcMatrix', right_on='Dynamic_spcMatrix' )
def OnImport3(self):
self.d = askopenfilename()
self.d = self.d.dropna(axis=0)
self.g = self.d.groupby('Dynamic_spcMatrix')['Attribute_spcName'].apply(lambda x: ', '.join(x.astype(str))) #join attributes usin commas
self.c['Attribute_spcName'] = self.c['Dynamic_spcMatrix'].map(g)
self.c = self.c[['Type', 'Name', 'Currency_spcCode', 'Product_spcCfg_spcModel_spcId', 'Product_spcName', 'Attribute_spcName', 'Matrix_spcType', 'Start_spcDate', 'End_spcDate', 'Original_spcList_spcPrice', 'Max_spcSale_spcPrice', 'Min_spcSale_spcPrice', 'String_spcMatrix_spcColumn_spc1', 'String_spcMatrix_spcColumn_spc2', 'String_spcMatrix_spcColumn_spc3', 'String_spcMatrix_spcColumn_spc4','Number_spcMatrix_spcColumn_spc1']]
def OnSaveAs(self):
self.dlg = asksaveasfilename(confirmoverwrite=False)
self.fname = self.dlg
if self.fname != '':
f = open(self.fname, "a")
new_text = time.time()
f.write(str(new_text)+'\n')
f.close()
self.c.to_csv(self.fname, index=False)
def OnChildClose(self):
self.wButton.config(state='normal')
self.top.destroy()
if __name__ == "__main__":
window = Window(None)
window.title("Create Csv")
window.mainloop()
它在导入2的中给出以下错误:
self.c = self.a.OnImport.merge(self.b, how='left', left_on='Dynamic_spcMatrix', right_on='Dynamic_spcMatrix' )
AttributeError:“unicode”对象没有属性“merge”
我是python和所有其他语言的初学者。你能帮我解决这个问题吗?就像asksaveasfilename
一样,askopenfilename
返回一个字符串(Python2在用于(可能)存储非ASCII文本时调用unicode
)。如果您想从中读取(CSV数据),您必须明确地通过用于合并/输出的pandas
来执行此操作。您希望self.a.merge
做什么?合并两个CSV文件(a和b):(可能是我错了。@fuzzedbycodec你能进一步解释一下吗?@Davis:)@sithara:你得说得更具体些;除了“文件名及其内容不同”之外,您还需要什么(thnku@Davis)