将该代码实现结果的学生姓名用百家姓随机组成替代
时间: 2024-11-15 12:23:58 浏览: 14
如果你想用中国百家姓来替换学生的姓名,可以先准备一个包含百家姓的列表,然后随机选择姓氏与学号组合。这里是一个简单的例子:
```python
import pandas as pd
import random
# 定义百家姓列表
hundred_families = ['赵', '钱', '孙', '李', '周', '吴', '郑', '王', ...] # 这里省略了完整的列表,你需要提供一个包含所有姓氏的列表
# 创建随机数据
students_count = 100
data = []
for _ in range(students_count):
# 随机选择一个姓氏
family_name = random.choice(hundred_families)
# 组合为姓名(假设学号固定格式)
student_name = f'{family_name}00{_ + 1}'
data.append({'姓名': student_name,
'操作系统原理': np.random.randint(60, 101),
'高等数学': np.random.randint(60, 101),
'计算机网络': np.random.randint(60, 101),
'大学英语': np.random.randint(60, 101),
'Python语言': np.random.randint(60, 101)})
# 转换为DataFrame
df = pd.DataFrame(data)
# 存储到Excel文件
filename = "百家姓学生成绩单.xlsx"
sheet_name = "百家姓名单"
df.to_excel(filename, sheet_name=sheet_name, index=False)
```
在这个修改后的版本中,每次循环都会从百家姓列表中随机选择一个姓氏,然后与固定格式的“学号”组合生成新的姓名。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)