1

我想使用 FileChooser 将 csv 文件导入 python 并将其显示为数据框。这是代码,它不起作用。谢谢你的帮助。

def get_open_filename(self):

    filename = None
    chooser = gtk.FileChooserDialog("Open File...", self.window,
                                    gtk.FILE_CHOOSER_ACTION_OPEN,
                                    (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, 
                                     gtk.STOCK_OPEN, gtk.RESPONSE_OK))

    response = chooser.run()
    if response == gtk.RESPONSE_OK: 
        with open(chooser.get_filename(), 'rb') as csvfile:
            don = DataFrame.from_csvfile(csvfile)           ## I am confused here !!!
            print don
    chooser.destroy()

    return filename
4

1 回答 1

1

我相信 from_csv 文件采用文件名而不是文件,使用这些文档 尝试替换

with open(chooser.get_filename(), 'rb') as csvfile:
    don = DataFrame.from_csvfile(csvfile)           ## I am confused here !!!
    print don

    don = DataFrame.from_csvfile(chooser.get_filename())
    print don
于 2013-08-02T09:50:38.680 回答