方法优化
import pandas as pd
def age_18_to_30(a):
return 18<=a<30
def level_a(s):
return 85<=s<=100
students = pd.read_excel('students.xlsx', index_col='ID')
students = students.loc[students['Age'].apply[age_18_to_30]].loc[students['Score'].apply[level_a]]
# 方法二students.loc[students.Age.apply[age_18_to_30].loc[students.Score.apply[level_a]]
import pandas as pd
students = pd.read_excel('students.xlsx', index_col='ID')
students = students.loc[students.Age.apply[lambda a : 18<=a<30]] \
.loc[students.Score.apply[lambda s:85 s <=100]]
# 空格正斜线 换行