I have a dataframe which is like as shown below
df1_new = pd.DataFrame({'person_id': [1, 1, 3, 3, 5, 5],'obs_date': ['7/23/2377 12:00:00 AM', 'NA-NA-NA NA:NA:NA', 'NA-NA-NA NA:NA:NA', '7/27/2277 12:00:00 AM', '7/13/2077 12:00:00 AM', 'NA-NA-NA NA:NA:NA']})
As you can see few of my date values are out of bound
values. However, I would still like to retain them as it is. Unfortunately, I couldn't due to OOB issue
I tried below
pd.to_datetime(df1_new['obs_date'], format='%m/%d/%Y %I:%M:%S %p', errors='coerce')
Is there any other efficient way to retain the date value as is but by changing the format alone? I am fine if it can be string column/datatype
I expect my output to be like as shown below.
updated try/except screenshot
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…