Jubilant Data Analyzer Python GUI
👤 Sharing: AI
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import io
import base64
from PIL import Image, ImageTk
class DataAnalyzerApp:
def __init__(self, root):
self.root = root
self.root.title("Jubilant Data Analyzer")
self.root.geometry("800x600")
self.df = None
# --- Main Frame ---
self.main_frame = ttk.Frame(self.root, padding=10)
self.main_frame.pack(fill=tk.BOTH, expand=True)
# --- Load Data Button ---
self.load_button = ttk.Button(self.main_frame, text="Load CSV Data", command=self.load_data)
self.load_button.pack(pady=10)
# --- Data Display ---
self.data_tree = ttk.Treeview(self.main_frame, columns=('Column 1'), show='headings')
self.data_tree.pack(fill=tk.BOTH, expand=True)
# --- Analysis Options ---
self.analysis_frame = ttk.LabelFrame(self.main_frame, text="Analysis Options", padding=10)
self.analysis_frame.pack(fill=tk.BOTH, pady=10)
self.summary_button = ttk.Button(self.analysis_frame, text="Show Summary Statistics", command=self.show_summary)
self.summary_button.pack(side=tk.LEFT, padx=5)
self.plot_button = ttk.Button(self.analysis_frame, text="Generate Plots", command=self.generate_plots)
self.plot_button.pack(side=tk.LEFT, padx=5)
# --- Details Button ---
self.details_button = ttk.Button(self.main_frame, text="Details", command=self.show_details)
self.details_button.pack(pady=10)
def load_data(self):
file_path = filedialog.askopenfilename(filetypes=[("CSV files", "*.csv")])
if file_path:
try:
self.df = pd.read_csv(file_path)
self.populate_treeview()
except Exception as e:
messagebox.showerror("Error", f"Could not load data: {e}")
def populate_treeview(self):
# Clear existing data
for item in self.data_tree.get_children():
self.data_tree.delete(item)
# Configure columns
self.data_tree['columns'] = list(self.df.columns)
for col in self.df.columns:
self.data_tree.heading(col, text=col)
self.data_tree.column(col, width=100) # Adjust width as needed
# Insert data
for index, row in self.df.iterrows():
self.data_tree.insert('', 'end', values=list(row))
def show_summary(self):
if self.df is not None:
try:
summary = self.df.describe().to_string()
messagebox.showinfo("Summary Statistics", summary)
except Exception as e:
messagebox.showerror("Error", f"Could not generate summary: {e}")
else:
messagebox.showinfo("Info", "Please load data first.")
def generate_plots(self):
if self.df is not None:
try:
# Create a new window for plots
plot_window = tk.Toplevel(self.root)
plot_window.title("Data Plots")
# Iterate through columns and create histograms
for col in self.df.columns:
if pd.api.types.is_numeric_dtype(self.df[col]):
fig, ax = plt.subplots()
self.df[col].hist(ax=ax)
ax.set_title(f"Histogram of {col}")
ax.set_xlabel(col)
ax.set_ylabel("Frequency")
# Embed plot in Tkinter window
canvas = FigureCanvasTkAgg(fig, master=plot_window)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
except Exception as e:
messagebox.showerror("Error", f"Could not generate plots: {e}")
else:
messagebox.showinfo("Info", "Please load data first.")
def show_details(self):
details_text = """
Jubilant Data Analyzer is a versatile tool designed for quick data exploration and analysis.
It allows users to load CSV files, display the data in a tabular format, and generate basic summary statistics and histograms.
Features:
- Load data from CSV files.
- Display data in a scrollable Treeview.
- Generate summary statistics (mean, median, etc.).
- Create histograms for numerical columns.
This application utilizes the following libraries:
- tkinter: For the GUI.
- pandas: For data manipulation and analysis.
- matplotlib: For generating plots.
"""
messagebox.showinfo("Details", details_text)
if __name__ == "__main__":
root = tk.Tk()
app = DataAnalyzerApp(root)
root.mainloop()
👁️ Viewed: 9
Comments