编辑
2023-11-18
发癫
00
请注意,本文编写于 539 天前,最后修改于 539 天前,其中某些信息可能已经过时。

目录

操作sqlite
生成验证码
登录界面
数据分析可视化
读取CSV文件中的数据
提取季节和水果销售量数据
绘制折线图
绘制柱状图
绘制饼图
绘制散点图

操作sqlite

python
''' Author: yowayimono Date: 2023-11-18 16:11:04 LastEditors: yowayimono LastEditTime: 2023-11-18 16:16:11 Description: nothing ''' import sqlite3 import csv # 连接数据库 conn = sqlite3.connect('testbook.db') cursor = conn.cursor() # 创建学生信息表 cursor.execute("""CREATE TABLE IF NOT EXISTS student( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, department TEXT, age INTEGER, phone TEXT, qq TEXT); """) # 读取csv文件插入数据库 with open('test.csv',encoding='utf8') as f: reader = csv.DictReader(f) for row in reader: name = row['name'] department = row['department'] age = row['age'] phone = row['phone'] qq = row['qq'] cursor.execute( "INSERT INTO student (name, department, age, phone, qq) VALUES (?,?,?,?,?)", (name, department, age, phone, qq)) # 查询所有记录 cursor.execute("SELECT * FROM student") for line in cursor.fetchall(): print(line,'\n') # 修改记录 cursor.execute("UPDATE student SET age=? WHERE name=?", (28, "张三")) # 删除记录 cursor.execute("DELETE FROM student WHERE name=?", ["李四"]) # 关闭数据库连接 conn.commit() cursor.close() conn.close()

test.csv文件

csv
name,department,age,phone,qq 张三,计算机系,20,13000000000,123456 李四,外语系,21,15000000000,456789 王五,艺术系,22,18000000000,987654 赵六,体育系,23,13000000001,234567 孙齐,数学系,24,15000000001,345678 冯翔,生物系,25,18000000001,456123 陈七,化学系,26,13000000012,567890 于八,物理系,27,15000000012,654321 马九,音乐系,28,18000000012,147852 吴十,汉语系,29,18500000012,147258 高世芳,历史系,20,18700000012,258369 谢诗梅,铁工系,21,18900000012,369258 王婉如,法律系,22,19100000012,458796 赵昌恺,管理系,23,19300000012,963258 王东方,计算机系,24,19500000012,963258 张萌萍,汉语系,25,19700000012,963258 张强,设计系,21,19900000012,963258 刘宏伟,体育系,23,13000000013,963258 张超,环境系,20,15000000013,963258 李林,外语系,21,17000000013,963258 黄雨萍,艺术系,22,19000000013,963258 傅岩,物理系,23,21000000013,963258 王军,商务系,24,23000000013,963258 李娜,语言系,25,25000000013,963258 孙颖,心理系,21,27000000013,963258 张云帆,政法系,23,29000000013,963258 王晓雨,教育系,20,310000013,963258 王婷,建筑系,21,330000013,963258 祝颖,美术系,22,350000013,963258 于丽,信息系,23,370000013,963258 刘雪妮,艺术系,24,390000013,963258 李涵,传媒系,25,410000013,963258 赵鹏程,体育系,21,430000013,963258 姜亮,电影系,23,450000013,963258 马文杰,汉语系,20,470000013,963258 邓灵怡,数学系,21,490000013,963258 陈风,艺术系,22,510000013,963258 韩冰,英语系,23,530000013,963258 孙超,计算机系,24,550000013,963258 张玉凤,经济系,25,570000013,963258 刘芳,商务系,21,590000013,963258 陈伟强,管理系,23,610000013,963258 李丽英,植物系,20,630000013,963258 毛毅,汽车系,21,650000013,963258 赵欣然,设计系,22,670000013,963258 肖婷婷,法律系,23,690000013,963258

生成验证码

python
import random red_balls = random.sample(range(1,34), 6) red_balls.sort() blue_ball = random.randint(1,16) print("红球号码:", red_balls) print("蓝球号码:", blue_ball) ################################################################################## import random num1 = random.randint(0, 9) num2 = random.randint(0, 9) num3 = random.randint(0, 9) num4 = random.randint(0, 9) captcha = num1 * 1000 + num2 * 100 + num3 * 10 + num4 print("您的验证码是:", captcha) ################################################################################## import re with open('func.py') as f: text = f.read() funcs = re.findall('def ([a-zA-Z_][a-zA-Z0-9_]*)\(', text) print(funcs) ################################################################################## def func1(): pass def funk(): print('Funk') def func2(): pass

登录界面

python
import tkinter as tk from tkinter import ttk # 登录函数 def login(): user = entry_user.get() pwd = entry_pwd.get() if user=="admin" and pwd=="123456": label_info["text"] = "登录成功" else: label_info["text"] = "用户名或密码错误" # GUI代码 window = tk.Tk() window.title("登录窗口") # 标签 label_user = tk.Label(window, text="用户名:") label_pwd = tk.Label(window, text="密码:") label_info = tk.Label(window) # 入口框 entry_user = tk.Entry(window) entry_pwd = tk.Entry(window) # 按钮 button_login = tk.Button(window, text="登录", command=login) button_exit = tk.Button(window, text="退出", command=window.quit) # 布局 label_user.grid(row=0, column=0) entry_user.grid(row=0, column=1) label_pwd.grid(row=1, column=0) entry_pwd.grid(row=1, column=1) button_login.grid(row=2, column=1) button_exit.grid(row=2, column=0) label_info.grid(row=3, column=1) window.mainloop()

数据分析可视化

python
''' Author: yowayimono Date: 2023-11-18 16:38:21 LastEditors: yowayimono LastEditTime: 2023-11-18 16:38:25 Description: nothing ''' import csv import matplotlib.pyplot as plt # 读取CSV文件中的数据 data = [] with open('xx.csv', 'r') as csvfile: reader = csv.reader(csvfile) next(reader) # 跳过表头 for row in reader: data.append(row) # 提取季节和水果销售量数据 seasons = [row[0] for row in data] sales = [int(row[1]) for row in data] # 绘制折线图 plt.plot(seasons, sales) plt.xlabel('Season') plt.ylabel('Sales') plt.title('Fruit Sales by Season') plt.show() # 绘制柱状图 plt.bar(seasons, sales) plt.xlabel('Season') plt.ylabel('Sales') plt.title('Fruit Sales by Season') plt.show() # 绘制饼图 plt.pie(sales, labels=seasons, autopct='%1.1f%%') plt.title('Fruit Sales by Season') plt.show() # 绘制散点图 plt.scatter(seasons, sales) plt.xlabel('Season') plt.ylabel('Sales') plt.title('Fruit Sales by Season') plt.show() #######################################################################################data Season,Sales Spring,120 Summer,180 Autumn,150 Winter,90

本文作者:yowayimono

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!