Home > Blockchain >  how to find Max date in pandas with NaN values
how to find Max date in pandas with NaN values

Time:06-07

I did spend few hours trying to find solution for my question and was not able to find any good working solution. I have Pandas table and i need to find Max Date from date column:

0    2022-07-07
1           NaN
2    2022-07-08
3           NaN
4    2022-07-10

I'm trying something like that:

df['date'].max()  -> "Not supported between instances "srt" and "float""

I also tried add numeric_only=true and then is_nan=True

Then even numpy way: numpy.nanmax(df.iloc['date'].value) -> cannot index by location index

Can someone tell me how to use Pandas and get MAX value from 1 column, if there is some strings and NaN in it??

thank you,

CodePudding user response:

you first need to convert to a datetime object then find maximum:

pd.to_datetime(df['date']).max()
Timestamp('2022-07-10 00:00:00')
  • Related