import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def read_data(file_path):
df = pd.read_csv(file_path)
df['datetime'] = pd.to_datetime(df['datetime'])
df.set_index('datetime', inplace=True)
return df
def calculate_pass_rate(df):
pass_count = df[df['result'] == 'Pass'].count()
total_count = df.count()
pass_rate = pass_count / total_count * 100
return pass_rate
def generate_warning(df):
warnings = []
for index, row in df.iterrows():
if row['warning']:
warnings.append(row['warning'])
return warnings
def analyze_data(file_path):
df = read_data(file_path)
pass_rate = calculate_pass_rate(df)
warnings = generate_warning(df)
print(f"Pass rate: {pass_rate}%")
if warnings:
print("Warnings:")
for warning in warnings:
print(warning)
else:
print("No warnings.")
# Plot the pass rate over time
plt.figure(figsize=(10, 6))
plt.plot(df.index, calculate_pass_rate(df), marker='o')
plt.xlabel('Date')
plt.ylabel('Pass Rate (%)')
plt.title('Quality Data Analysis')
plt.grid(True)
plt.show()
analyze_data('quality_data.csv')
import tkinter as tk
from tkinter import ttk
# 创建顶层窗口
root = tk.Tk()
root.title("Quality Data Analyzer")
# 创建标题栏
title_bar = ttk.Label(root, text="Quality Data Analyzer", font=("Arial", 18))
title_bar.pack(fill=tk.X)
# 创建按钮
button_quit = ttk.Button(root, text="Quit", command=root.quit)
button_quit.pack(fill=tk.X, side=tk.RIGHT)
# 创建主体区域
main_frame = ttk.Frame(root)
main_frame.pack(fill=tk.BOTH, expand=True)
# 创建数据展示区域
data_canvas = tk.Canvas(main_frame, width=600, height=400)
data_canvas.pack()
# 创建交互元素
slider_value = tk.StringVar()
slider = ttk.Scale(main_frame, from_=0, to=100, orient=tk.HORIZONTAL, variable=slider_value)
slider.pack()
button_export = ttk.Button(main_frame, text="Export", command=lambda: print("Export clicked"))
button_export.pack()
# 创建对话框
dialog = tk.Toplevel()
dialog.title("Dialog")
label = tk.Label(dialog, text="This is a dialog")
label.pack()
button_ok = ttk.Button(dialog, text="OK", command=dialog.destroy)
button_ok.pack()
# 运行窗口
root.mainloop()
标签:plt,df,rate,可视化,tk,pass,pack From: https://www.cnblogs.com/CLGYPYJ/p/17626258.html