AttributeError: 'unicode' object has no attribute 'merge'

AttributeError: 'unicode' object has no attribute 'merge'

这是我的代码:

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()

它在 OnImport2 中给出以下错误:

self.c = self.a.OnImport.merge(self.b, how='left', left_on='Dynamic_spcMatrix', right_on='Dynamic_spcMatrix' )

AttributeError: 'unicode' object has no attribute 'merge'

我是 python 和所有其他语言的初学者。你能帮我解决这个问题吗?

就像 asksaveasfilenameaskopenfilename returns 一个字符串(Python 2 在用于(可能)存储 non-ASCII 文本)。如果你想读取(CSV 数据)它,你必须明确地这样做——大概是通过你正在使用 merging/output.

pandas