如何解决Pandastable将新列添加到现有数据框
我正在尝试在脚本中使用pandastable
库。基本上,以下脚本将用户选择的.csv
导入到pandastable
中,并正确显示在tkinter
GUI上。
一旦导入,我想添加列。我认为使用此文档 https://pandastable.readthedocs.io/en/latest/examples.html#basics 及其列出的表格方法将很容易。例如:table.autoAddColumns(1)
仅添加一列,但是无论我如何尝试和使用它,我都无法使其正常工作。
import csv
import tkinter as tk
import tkinter.ttk as tkrttk
from tkinter import *
from tkinter import filedialog
import pandas as pd
from pandastable import Table,TableModel
from PIL import Image,ImageFont,ImageTk
root = tk.Tk()
root.geometry("2000x1000")
root.title('Workshop Manager')
style = tkrttk.Style()
style.configure("Treeview.Heading",foreground='Red',font=('Helvetica',10))
def select_input_file():
global input_file_path
input_file_path = filedialog.askopenfilename(
filetypes=(("CSV files","*.csv"),))
app = TestApp(root,input_file_path)
app.place(bordermode = INSIDE,height = 500,width = 2000,x =0,y=50)
class TestApp(tk.Frame):
def __init__(self,parent,input_file_path):
super().__init__(parent)
self.table = Table(self,showtoolbar=False,showstatusbar=False)
self.table.importCSV(input_file_path)
self.table.show(input_file_path)
##Breaks here##
self.table.autoAddColumns(1)
root.mainloop()
我尝试使用table.autoAddColumns(1)
。这也不起作用。
如果我使用self.table.autoAddColumns(1)
,则会收到错误消息AttributeError: 'TableModel' object has no attribute 'auto_AddColumns'
如果我使用table.autoAddColumns(1)
,则会收到错误消息NameError: name 'table' is not defined
解决方法
这是pandastable
中的错误。
但是,您可以改为使用addColumn()
函数。在不带参数的情况下调用它时,将显示一个对话框来选择dtype
并输入新列的名称。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。