0

I am trying to display a dataframe in a frame on my tkinter app. I want to group my values by the first 2 columns and get the sum of all the values per unique pair. While working with the dataframe everything is working as expected. Printed in the terminal, my output is exactly what I want, however when displayed in the tkinter frame it cuts off the columns that I group.

This is what I have tried so far:

import pandas as pd
import tkinter as tk
from pandastable import Table

df = pd.DataFrame({
    'A': ['A', 'B', 'A', 'A', 'B', 'B'],
    'B': ['a', 'a', 'a', 'b', 'b', 'a'],
    'C': [3, 1, 4, 1, 5, 9]
})

def order(df):
    ordered = df.groupby(['A', 'B']).sum()
    print(ordered)
    return ordered

root = tk.Tk()

frame = tk.Frame(root)
frame.pack()

pt = Table(frame, dataframe = order(df))
pt.show()

root.mainloop()

Here is a simplified version of what I'm trying to achieve. The first print gives me what I want: terminal screenshot

While the tkinter window cuts off columns A and B: tkinter screenshot

Any advice on how I could make the tkinter table look like the terminal output would be very much appreciated. Thanks :)

  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 11 '22 at 14:58

1 Answers1

1

I have fixed my problem, but I'll leave the question up anyway in case someone else is having similar difficulties. Adding as_index = False to groupby solved it.

cafce25
  • 15,907
  • 4
  • 25
  • 31