Python 3.x 从datetime列获取第二个最小值

Python 3.x 从datetime列获取第二个最小值,python-3.x,pandas,dataframe,Python 3.x,Pandas,Dataframe,我有一个带有日期时间列的数据帧,我可以使用 df['Date'].min() 我怎样才能得到第二个,第三个。。。最小值使用nlargest或nsmalest 第二大 series.nlargest(2).iloc[-1] 首先确保您的日期在datetime中: df['Sampled_Date'] = pd.to_datetime(df['Sampled_Date']) 然后删除重复项,取nsmallest(2),然后取其最后一个值: df['Sampled_Date'].drop_dup

我有一个带有日期时间列的数据帧,我可以使用

df['Date'].min()

我怎样才能得到第二个,第三个。。。最小值使用
nlargest
nsmalest

第二大

series.nlargest(2).iloc[-1]

首先确保您的日期在datetime中:

df['Sampled_Date'] = pd.to_datetime(df['Sampled_Date'])
然后删除重复项,取nsmallest(2),然后取其最后一个值:

df['Sampled_Date'].drop_duplicates().nsmallest(2).iloc[-1]

可能是重复的嘿,我有一个完整的工作答案你的Fast.com的问题,但问题被删除。如果你重新打开问题,我可以发布它吗?或者通过“我的信息”中的电子邮件与我联系,以您喜欢的为准。我已经为您创建了一个问题并写了详细的答案: