我確實花了幾個小時試圖為我的問題找到解決方案,但找不到任何好的作業解決方案。我有 Pandas 表,我需要從日期列中找到 Max Date:
0 2022-07-07
1 NaN
2 2022-07-08
3 NaN
4 2022-07-10
我正在嘗試這樣的事情:
df['date'].max() -> "Not supported between instances "srt" and "float""
我也試過添加numeric_only=true然后is_nan=True
然后甚至是麻木的方式:numpy.nanmax(df.iloc['date'].value) -> cannot index by location index
有人可以告訴我如何使用 Pandas 并從 1 列中獲取 MAX 值,如果其中有一些字串和 NaN?
謝謝你,
uj5u.com熱心網友回復:
您首先需要轉換為datetime物件,然后找到最大值:
pd.to_datetime(df['date']).max()
Timestamp('2022-07-10 00:00:00')
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/487611.html
下一篇:我收到此錯誤-->AttributeError:'NoneType'objecthasnoattribute'predict'
