[英]Pandastable add new column to existing dataframe
I am trying to use the pandastable
library within my script.我正在尝试在我的脚本中使用
pandastable
库。 Basically the below script imports the user chosen .csv
into a pandastable
and displays correctly on tkinter
GUI.基本上,以下脚本进口用户选择
.csv
成pandastable
和显示正确上tkinter
GUI。
Once imported I would like to add columns.导入后,我想添加列。 I assumed this would be easy enough using this doc https://pandastable.readthedocs.io/en/latest/examples.html#basics and its listed table methods.
我认为使用此文档https://pandastable.readthedocs.io/en/latest/examples.html#basics及其列出的表格方法会很容易。 Eg:
table.autoAddColumns(1)
to add a single column(s), however no matter how i try and use it I cant get it to work..例如:
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()
I have tried using table.autoAddColumns(1)
.我试过使用
table.autoAddColumns(1)
。 This didnt work either.这也不起作用。
If I use self.table.autoAddColumns(1)
I get error AttributeError: 'TableModel' object has no attribute 'auto_AddColumns'
如果我使用
self.table.autoAddColumns(1)
我得到错误AttributeError: 'TableModel' object has no attribute 'auto_AddColumns'
If I use table.autoAddColumns(1)
I get error NameError: name 'table' is not defined
如果我使用
table.autoAddColumns(1)
我得到错误NameError: name 'table' is not defined
It is a bug in pandastable
.这是
pandastable
一个错误。
However you can use addColumn()
function instead.但是,您可以改用
addColumn()
函数。 When it is called without argument, a dialog will be shown to select the dtype
and input the name of the new column.当它被无参数调用时,将显示一个对话框来选择
dtype
并输入新列的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.