Home>

I'm stumbling on knock 42 in "python practice data analysis 100 knocks".
I'm copying the code as it is, but for some reason I get the following error.
AttributeError: Can only use .dt accessor with datetimelike values
There seems to be no mistake in printing the book.

from dateutil.relativedelta import relativedelta
exit_customer = customer.loc [customer ["is_deleted"] == 1]
exit_customer ["exit_date"] = None
exit_customer ["end_date"] = pd.to_datetime (exit_customer ["end_date"], errors = "coerce")
for i in range (len (exit_customer)):
exit_customer ["exit_date"] .iloc [i] = exit_customer ["end_date"] .iloc [i] --relativedelta (months = 1)
exit_customer ["year/month"] = exit_customer ["exit_date"] .dt.strftime ("% Y% m")
uselog ["year/month"] = uselog ["year/month"] .astype (str)
exit_uselog = pd.merge (uselog, exit_customer, on = ["customer_id", "year/month"], how = "left")
print (len (uselog))
exit_uselog.head ()

Am I doing something wrong? please tell me.