Add Descriptive.py|Show all data descriptive stat

This commit is contained in:
Sirin Puenggun 2023-05-12 15:35:35 +07:00
parent 1e528e3a65
commit 1b918d88ef

31
Essential/descriptive.py Normal file
View File

@ -0,0 +1,31 @@
import sqlite3
import tkinter as tk
from tkinter import ttk
import pandas as pd
class Descriptive:
def __init__(self, data):
self.data = data
def show_statistics(self):
statistics = self.data.describe()
window = tk.Toplevel()
tree = ttk.Treeview(window)
columns = statistics.columns.tolist()
tree["columns"] = columns
tree.heading("#0", text="Statistic")
for column in columns:
tree.heading(column, text=column)
for stat in statistics.index:
values = statistics.loc[stat].tolist()
tree.insert("", "end", text=stat, values=values)
tree.pack()
window.mainloop()
# df = pd.read_sql_query("SELECT * FROM food_data", sqlite3.connect(r"D:\Food-Nutrient-Viewer-Tkinter\Essential\data\food_data.db"))
# descriptive = Descriptive(df[['product_name', 'carbohydrates_100g','sugars_100g','energy-kcal_100g','fat_100g','proteins_100g']])
# descriptive.show_statistics()