数据过滤
正如您在视频课中所看到的,您可能会因为不同原因需要对数据进行过滤。
在本练习中,您将通过过滤来选取 DataFrame 的特定部分:
- 按每周中每天记录的条目数量进行筛选
- 按每周中每天顾客支付给餐厅的平均金额进行筛选
本练习是课程的一部分
使用 pandas 编写高效代码
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Filter the days where the count of total_bill is greater than $40
total_bill_40 = restaurant_data.groupby('day').____(lambda x: ____[____].____() > 40)
# Print the number of tables where total_bill is greater than $40
print('Number of tables where total_bill is greater than $40:', total_bill_40.shape[0])