itubay 发表于 2024-11-17 02:10:31

OneData.PyBuilder

本帖最后由 itubay 于 2024-11-18 23:30 编辑

共同一数据源构建不同Python项目的简单尝试:handshake

一份Excel在线文档:https://www.gairuo.com/file/data/dataset/team.xlsx
有兴趣的可以加入,一起学习进步

itubay 发表于 2024-11-17 02:17:42

#读取Excel文件生成Word

import numpy as np
import pandas as pd
import docx
from docx import Document
import requests
from io import BytesIO

url = 'https://www.gairuo.com/file/data/dataset/team.xlsx'

response = requests.get(url)
data = BytesIO(response.content)
df = pd.read_excel(data)
print(df)
doc = Document()
doc.add_heading('DataReport', level=1)
doc.add_paragraph('以下是从Excel读取的数据:')
for index, row in df.iterrows():
    doc.add_paragraph(f'{index}: {row}')
doc.save('ExcelReport.docx')


itubay 发表于 2024-11-17 02:25:45

本帖最后由 itubay 于 2024-11-17 02:31 编辑

#按team分组,统计每组人数(即不同姓名的人数),生成柱状统计图
import os,sys
import pandas as pd
import matplotlib.pyplot as plt
file = 'https://www.gairuo.com/file/data/dataset/team.xlsx'
df = pd.read_excel(file)
plt.rcParams['font.sans-serif' = ['SimHei'
plt.rcParams['legend.fontsize' = 12
gp=df.groupby("team")["name"].count()
df=pd.DataFrame(gp)
ax=df.plot(kind="bar",stacked=False,label="人数")
for i, value in enumerate(df['name']):
    plt.text(i, value, value, ha='center', va='bottom')
plt.legend(labels=["人数"])
plt.tight_layout()
plt.savefig(f"bar_chart3.png")
os.startfile(f"bar_chart3.png")




页: [1]
查看完整版本: OneData.PyBuilder