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('D:/output.xlsx', index_col='idx')
# 筛选出 年龄在18到30之间,成绩在85到100分之间的学员
students = students.loc[students['Age'].apply(age_18_to_30)].loc[students['Score'].apply(level_a)]
# 上一行的写法,也可以这样写
students = students.loc[students.Age.apply(age_18_to_30)].loc[students.Score.apply(level_a)]
# lambda 表达式写法
students = students.loc[students.Age.apply(lambda a : 18 <= a < 30)] \
.loc[students.Score.apply(lambda s : 85 <= s <= 100)]
print(students)
#books.to_excel('D:/output.xlsx')
视频链接:https://www.bilibili.com/video/av88814463?p=8
来源:oschina
链接:https://my.oschina.net/ski/blog/3179458