Problem: I have a pandas DataFrame, that has several columns. Some of the columns are strings as dates for example: ["A", "2019-12-01 00:00:00", "2020-01-01 00:00:00"]
Q:How does one choose the latest date column in this case, keeping in mind that the column location might be different at some point in time?
In the example case above, the latest date from ["A", "2019-12-01 00:00:00", "2020-01-01 00:00:00"]
would be "2020-01-01 00:00:00"
Possible solution: I was thinking of potentially doing a regex search to match the numbers and dashes and find the strings that adhere to the specific datetime format, using something like date_list = regex.match(columns)
then transform everything to datetime, find the max date by doing max_date = date_list.max()
and then df[str(max_date)]
Q: But maybe there's a sort-of-built-in-way or just-a-better-way to do this than the possible solution?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…