I have what has to be considered a syntax question.
Doing some data scrubbing, data contains date time fields.
Date is always present but sometimes the time is missing.
Like this:
3/1/2023 11:03 AM
4/8/2022 10:21 AM
7/19/2012
7/12/2021
4/16/2024 7:02 AM
So my simple mind says, if the full colon (:) is missing concat 00:00.
And we are done.
I expected this to work:
dfAssetMeter_a[‘lastReadingDTFixed’] = dfAssetMeter_a[‘LASTREADINGDATE’].astype(str) if dfAssetMeter_a[‘LASTREADINGDATE’].astype(str).find(‘:’) > 0 else dfAssetMeter_a[‘LASTREADINGDATE’].astype(str) + ’00:00 AM’
Did not work
This works:
def fixDateTime(dateStr_in):
return dateStr_in if dateStr_in.find(‘:’) > 0 else dateStr_in + ‘ 12:00 AM’
dfAssetMeter_a[‘lastReadingDTFixed’] = dfAssetMeter_a[‘LASTREADINGDATE’].apply( fixDateTime )
Questions:
Which is more correct “Python” way to do this?
In my mind, method two would be easier to understand at three on a Friday , before a holiday weekend.
Please I do not want to start a battle royal here!
Would somebody be kind enough to provide the correct syntax for the first method.
Thanks for your kind attention.
Please be kind to the newbie
KD