Pandas TypeError: unsupported operand type(s) for /: 'str' and 'int'
Pandas TypeError: unsupported operand type(s) for /: 'str' and 'int'
我正在分析学生的表现,我想统计数学成绩高于80的学生的百分比,我将分数从string转换为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"]
我正在分析学生的表现,我想统计数学成绩高于80的学生的百分比,我将分数从string转换为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"]