1. 读取学生信息表:使用 pandas 读取 Excel 或 CSV 文件。示例代码:python复制import pandas as pd
df = pd.read_excel('student_info.xlsx')
2. 同学性别饼状图:使用 pyecharts 创建饼图。示例代码:python复制from pyecharts.charts import Pie
from pyecharts import options as opts
gender_counts = df['性别'].value_counts()
pie = Pie()
pie.add("", [list(z) for z in zip(gender_counts.index, gender_counts.values)])
pie.set_global_opts(title_opts=opts.TitleOpts(title="性别分布"))
pie.render("gender_pie.html")
3. 同学所在省份中国地图可视化:使用 pyecharts 的地图组件。示例代码:python复制from pyecharts.charts import Map
from pyecharts import options as opts
province_counts = df['省份'].value_counts()
map_chart = Map()
map_chart.add("", [list(z) for z in zip(province_counts.index, province_counts.values)], "china")
map_chart.set_global_opts(title_opts=opts.TitleOpts(title="省份分布"))
map_chart.render("province_map.html")
4. 所在城市柱状图:使用 pyecharts 的柱状图组件。示例代码:python复制from pyecharts.charts import Bar
city_counts = df['城市'].value_counts()
bar = Bar()
bar.add_xaxis(city_counts.index.tolist())
bar.add_yaxis("城市分布", city_counts.values.tolist())
bar.set_global_opts(title_opts=opts.TitleOpts(title="城市分布"))
bar.render("city_bar.html")
5. 签名词云:使用 wordcloud 和 matplotlib 。示例代码:python复制from wordcloud import WordCloud
import matplotlib.pyplot as plt
signatures = ' '.join(df['签名'].dropna())
wordcloud = WordCloud(width=800, height=400, background_color='white').generate(signatures)
plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.savefig("signature_wordcloud.png")
6. 成绩分布折线图:使用 pyecharts 的折线图组件。示例代码:python复制from pyecharts.charts import Line
scores = df['成绩'].value_counts().sort_index()
line = Line()
line.add_xaxis(scores.index.tolist())
line.add_yaxis("成绩分布", scores.values.tolist())
line.set_global_opts(title_opts=opts.TitleOpts(title="成绩分布"))
line.render("score_line.html")
7. 宿舍分布关系图:使用 networkx 和 matplotlib 。示例代码:python复制import networkx as nx
import matplotlib.pyplot as plt
dorm_data = df.groupby('宿舍')['姓名'].apply(list)
G = nx.Graph()
for dorm, names in dorm_data.items():
for i in range(len(names)):
for j in range(i+1, len(names)):
G.add_edge(names[i], names[j], dorm=dorm)
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels=True, node_size=3000, node_color="skyblue", font_size=10)
plt.savefig("dorm_network.png")
8. 人脸头像用腾讯云识别:使用腾讯云 API 进行人脸识别。示例代码:python复制import requests
import base64
def recognize_face(image_path, api_key, api_secret):
with open(image_path, 'rb') as f:
img_data = f.read()
img_base64 = base64.b64encode(img_data).decode('utf-8')
url = "https://api.tencentcloud.com/v2/face/face_detect"
params = {
"ImageBase64": img_base64,
"ApiKey": api_key,
"ApiSecret": api_secret
}
response = requests.post(url, json=params)
return response.json()
# 示例调用
result = recognize_face("example.jpg", "your_api_key", "your_api_secret")
print(result). 项目总结:通过本次实践,我们成功实现了对班级学生信息的多维度分析和可视化。使用 pyecharts 和其他可视化工具,我们能够直观地展示数据分布和关系。腾讯云的人脸识别功能为数据分析增添了新的维度。2. 未来展望:功能扩展:考虑加入更多交互式元素,如允许用户筛选和动态更新图表。性能优化:针对大数据集,探索更高效的数据处理和可视化方法。跨平台支持:确保可视化结果在不同设备和浏览器上的一致性。