0

I have a df pandas.core.series.Series such that:

0        11/8/16
1        11/8/16
2        6/12/16
3       10/11/15
4       10/11/15
          ...   
9989     1/21/14
9990     2/26/17
9991     2/26/17
9992     2/26/17
9993     12/30/17

If I use max() on it, it shows the latest date as '9/9/17', instead of the actual maximum which is, in this case '12/30/17'.

I understand why it is happens - because 9 > 1.

How can I fix it?

2
  • 1
    I'd suggest using datetime.strptime to convert those to date objects for comparison. Commented Mar 31, 2022 at 20:27
  • 2
    This doesn't look like a numpy array. What exactly is the object? Can you provide the code to construct it? Commented Mar 31, 2022 at 20:27

1 Answer 1

1

Convert the dates to timestamps first:

import pandas as pd
df["date"] = pd.to_datetime(df["date"], format="%m/%d/%y")
>>> df["date"].max()
Sign up to request clarification or add additional context in comments.

2 Comments

This would work, but it would be good to indicate when using 3rd party libraries that require installation, like pandas.
What OP provided looks like a pandas.Series and not an "array" as they claim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.