Sometimes when I'm running a python code in Google Colab and it runs in the first place, turns out that in the 2nd or 3rd attempt this same chunk of code for unknown reasons gives an error, as if the code was wrong (even though nothing has been modified). As soon as I disconnect and restart the notebook, the exact same chunk of code runs normally, again without modifications. Has anyone already come across this issue and know how to fix it?
import datetime #1st chunk
def convert_date(x): #2nd chunk
y= x.split(' ')[0]
return datetime.datetime(int(y.split('/')[2]),int(y.split('/')[1]),int(y.split('/')[0]))
hr['Hire Date'] = hr['Hire Date'].map(lambda x: convert_date(x)) #3rd chunk
When running the 3rd chunk it gives the error: AttributeError: 'Timestamp' object has no attribute 'split'
CodePudding user response:
Is because you already applied the transformation to that column. Reload your data instead of restarting the kernel and it will work again.