Comparing 2 "datetime" Columns in Pandas
I have 2 datetime columns in .csv file.
I want to compare the dates and times in both columns.
e.g., columns A and B have data in datetime format. I need to write a code that:
-compares the date and hour time in both columns.
-if the datetime in column A is before datetime in column B, then an error is reported.
-then I'll replace those data, in order that the datetime in column A should be always after the datetime in column B.
N.B. I'm a beginner in python and pandas.
one way to do it would be to first get the location of the faulty rows:
faulty_rows = dataframe['A'] < dataframe['b']
then replace these rows with a value that you'd like:
delta = timedelta(seconds=1)
dataframe.loc[faulty_rows, "A"] = dataframe.loc[faulty_rows, "B"] + delta
you can replace delta with whatever value you'd want