I have this csv file "rfm_data.csv":
CustomerID PurchaseDate TransactionAmount ProductInformation
8814 11-04-23 943.31 Product C
2188 11-04-23 463.70 Product A
4608 11-04-23 80.28 Product A
2559 11-04-23 221.29 Product A
I read and transform data with this code:
data = pd.read_csv("rfm_data.csv")
data['PurchaseDate'] = pd.to_datetime(data['PurchaseDate'], format='%d-%m-%y')
data['Recency'] = (datetime.now().date() - data['PurchaseDate'].dt.date).dt.days
When I print (data) I get this error message:
AttributeError: Can only use .dt accessor with datetimelike values. Did you mean: 'at'?
If I delete the dt.day from the last line of code I got this result:
CustomerID PurchaseDate TransactionAmount ProductInformation Recency
8814 2023-04-11 943.31 Product C 140 days, 0:00:00
2188 2023-04-11 463.70 Product A 140 days, 0:00:00
4608 2023-04-11 80.28 Product A 140 days, 0:00:00
2559 2023-04-11 221.29 Product A 140 days, 0:00:00
But what I want in [Recency] is only the number of days to make further calculations.
format='%y-%m-%d'?