本文同步发表于小弟自架网站:微确幸资讯站
以下程式码源自于ChatGPT,主要变数说明如下:
n_students:学生人数
n_exams:考试科目数
mean:考试成绩平均数
std_dev:考试成绩标準差
import pandas as pdimport numpy as np# Set the number of students and the number of examsn_students = 20n_exams = 5# Set the mean and standard deviation for the normal distributionmean = 70std_dev = 10# Generate the random scores using numpyscores = np.random.normal(loc=mean, scale=std_dev, size=(n_students, n_exams))# Create a pandas DataFrame to store the scoresdf = pd.DataFrame(scores)# Set the column namesdf.columns = ['Exam ' + str(i+1) for i in range(n_exams)]# Set the row names as the student IDsdf.index = ['Student ' + str(i+1) for i in range(n_students)]# Print the DataFrameprint(df)