Good morning! I am trying to convert a column that has multiple dates in various formats into a datetime column.
import pandas as pd
data = {
'c1':['2020/10/01','10/01/2020','10/1/2020','31/08/2020','12-21-2020','5-3-2020','05-03-2020','ERRER']
}
df = pd.DataFrame (data, columns = ['c1'])
The code above creates my dataframe to test on. If I run the following code, I get an error because 'ERRER' is not a valid date:
df['c2'] = df.apply(lambda x: pd.to_datetime(x['c1']), axis=1)
Is there a way to skip a row in the apply function if it can't be converted to a datetime? Or convert error rows to a default date (i.e. '1900-01-01')?