看过来
《pandas 教程》 持续更新中,提供建议、纠错、催更等加作者微信: gr99123(备注:pandas教程)和关注公众号「盖若」ID: gairuo。跟作者学习,请进入 Python学习课程。欢迎关注作者出版的书籍:《深入浅出Pandas》 和 《Python之光》。
(编码题)物流部记录了 2024-08-01 到 2024-08-10 的每日配送延迟分钟数:
import pandas as pd
import numpy as np
delay = pd.Series(
[12, 5, 18, 7, 22, 9, 6, 15, 8, 11],
index=pd.date_range('2024-08-01', periods=10, freq='D'),
name='延迟(分钟)'
)
任务:
argmin()
找出 延迟最小 的日期。argmax()
找出 延迟最大 的日期。代码如下:
best_day = delay.index[delay.argmin()]
worst_day = delay.index[delay.argmax()]
print("延迟最小日期:", best_day) # 2024-08-02
print("延迟最大日期:", worst_day) # 2024-08-05
(完)
更新时间:2025-08-21 14:53:19 标签:pandas python 最大值 最小值