Pandas 类型错误:不支持 /的操作数类型:"str"和"int"



我正在分析学生的表现,我想计算数学成绩高于80的学生的百分比,我将分数从字符串转换为int,但我仍然得到一个错误。为什么?

import pandas as pd 
df = pd.read_csv('Data/StudentsPerformance.csv')
df['math_score'] = df['math_score'].astype(int)
filt = (df['math_score'] >= 80)
higherthan80 = df.loc[filt]
respond_count = df.gender.count()
part = higherthan80 / respond_count

现在,您正在尝试将整个数据帧划分为respond_count。尝试只取math_score字段。

higherthan80 = df.loc[df['math_score'] >= 80, "math_score"]

最新更新