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))
Am I doing something wrong? please tell me.
Answer # 1
It succeeded when the following part was deleted.
.dt.strftime ("% Y% m")
- python - i don't know the solution and cause of the attribute error that occurred when using pillow
- python - how to resolve attribute error
- how to calculate datetime in python ~ datetime error ~
- python - "type error: expect dataindex as datetime index" error does not disappear
- python - the py file cannot be executed in the task scheduler 0x2 error
- [python] graphviz output format error
- python - categorical_crossentoropy error does not resolve
- readcsv error in python
- python - i want to display an image with pysimplegui, but an error occurs
- python - error when scraping with selenium and firefox
- python 3x - best estimator: i get an error with no syntax, so please tell me what to do
- python - i get an error when connecting to a voice channel with discordpy
- python - error in image binarization using cv2adaptivethreshold function
- [python] i don't know how to solve the error
- python - an error has occurred in yolo v3
- python - idle cannot resolve the "rootgeometry" error
- python - tuple error does not resolve
- python max () arg is an empty sequence and an error occurs and it cannot be processed well
- python - in raspberry pi, the error occurs only in the case of the automatic start program using systemd
- python : How to translate unixtimestamp values at the date?
- python : Create a new column based on the content of another
- python - extract specific items from pandas table
- python - [pandas] how to write a data frame (including date data) to a spreadsheet cell
- i want to get the day of the week in python
- python - i want to collect time-series data, which is divided into lines for each hour, into each line for each day
- python - how to deal with error when converting pandas datetime type
- please tell me how to count the number of occurrences within the specified period of weekly or monthly with python!
- conversion between numeric and datetime types in python