Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: descriptor '__sub__' requires a 'datetime.datetime' object but received a 'str' #7

Open
soliverc opened this issue Apr 20, 2020 · 1 comment

Comments

@soliverc
Copy link

In line 16, the user specified end date was not converted to a datetime object. It was throwing an error. I fixed it manually by adding datetime.strptime(recency_end_date, '%m/%d/%y') around recency_end_date.

From the rfm_utils.py file:

Before:

def convert_transaction_to_user(df, recency_end_date=None):
    id_col = df.columns[0]
    date_col = df.columns[1]
    transaction_col = df.columns[2]
    df[date_col] = pd.to_datetime(df[date_col])

    if recency_end_date is not None:
        end_date = recency_end_date
    elif recency_end_date is None:
        end_date = datetime.today()

After

def convert_transaction_to_user(df, recency_end_date=None):
    id_col = df.columns[0]
    date_col = df.columns[1]
    transaction_col = df.columns[2]
    df[date_col] = pd.to_datetime(df[date_col])

    if recency_end_date is not None:
        end_date = **datetime.strptime(recency_end_date, '%m/%d/%y')**
    elif recency_end_date is None:
        end_date = datetime.today()
@soliverc
Copy link
Author

By the way I have no idea how to do a pull request. I attempted it but can't seem to figure it out. Gonna make another attempt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant