turned on flat screen monitor

Python學習筆記: 快速產生常態分佈(Normal distribution)的學生成績-源自ChatGPT

以下程式碼源自於ChatGPT,主要變數說明如下:

n_students:學生人數
n_exams:考試科目數
mean:考試成績平均數
std_dev:考試成績標準差

import pandas as pd
import numpy as np

# Set the number of students and the number of exams
n_students = 20
n_exams = 5

# Set the mean and standard deviation for the normal distribution
mean = 70
std_dev = 10

# Generate the random scores using numpy
scores = np.random.normal(loc=mean, scale=std_dev, size=(n_students, n_exams))

# Create a pandas DataFrame to store the scores
df = pd.DataFrame(scores)

# Set the column names
df.columns = ['Exam ' + str(i+1) for i in range(n_exams)]

# Set the row names as the student IDs
df.index = ['Student ' + str(i+1) for i in range(n_students)]

# Print the DataFrame
print(df)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *