简体   繁体   中英

Pandastable add new column to existing dataframe

I am trying to use the pandastable library within my script. Basically the below script imports the user chosen .csv into a pandastable and displays correctly on 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. 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..

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) . This didnt work either.

If I use self.table.autoAddColumns(1) I get error AttributeError: 'TableModel' object has no attribute 'auto_AddColumns'

If I use table.autoAddColumns(1) I get error NameError: name 'table' is not defined

It is a bug in pandastable .

However you can use addColumn() function instead. When it is called without argument, a dialog will be shown to select the dtype and input the name of the new column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM