我正在尝试在 Jupyter Lab 上运行下面的代码块。
import csv
import statistics
smoker = []
non_smoker = []
with open('insurance.csv', 'r') as insurance_file:
fieldnames = ['age', 'sex', 'bmi', 'children', 'smoke', 'region', 'charges']
csv_reader = csv.DictReader(insurance_file, delimiter = ',', skipinitialspace=True,
fieldnames = fieldnames)
for status in insurance_file:
if ['smoke'] == 'yes':
smoker.append(float(row['age']))
elif ['smoke'] == 'no':
non_smoker.append(float(row['age']))
##Import libraries
from numpy import percentile
from numpy.random import rand
##Calculate Values
quartiles_smoker = percentile(smoker, [25, 50, 75])
quartiles_non_smoker = percentile(non_smoker[25, 50, 75])
data_min_smoker, data_max_smoker = data.min(smoker), data.max(smoker)
data_min_nonsmoker, data_max_nonsmoker = data.min(non_smoker), data.max(non_smoker)
每次运行时,都会收到以下消息: Desktop/Untitled.ipynb 的内核似乎已经死了。它会自动重启。
当我运行从 smoker = []
到 from numpy.random import rand
的块时,它工作正常,但是当我运行计算时,出现错误。这是我电脑内部的问题还是我的代码有问题?