crawlers
crawlers

Reputation: 47

python loyalt point expire date calculation

for below dataset i need to calcute email based points expire date.Normally expire date is create+366 days but If customer makes another purchase within 365 days previouse expire dates shoul be automatilly update same as last purchase's expire date. If there is more than 365 days nothing is change for previous expire dates, it should e iteratives.

data = """date_created,first_name,last_name,email,description,points_x,expire_date
20.01.2020,namex,surenamex,test@hotmail.com,Make a Purchase,74,
20.01.2022,namex,surenamex,test@hotmail.com,Double Points for Sale,148,
3.02.2022,namex,surenamex,test@hotmail.com,Make a Purchase,70,
10.02.2022,namex,surenamex,test@hotmail.com,Duplicate Campaign,-74,
23.02.2022,namex,surenamex,test@hotmail.com,Make a Purchase,0,
20.01.2020,namey,surenamey,test2@hotmail.com,Make a Purchase,74,
20.01.2022,namey,surenamey,test2@hotmail.com,Double Points for Sale,148,
3.02.2022,namey,surenamey,test2@hotmail.com,Make a Purchase,70,
10.02.2022,namey,surenamey,test2@hotmail.com,Duplicate Campaign,-74,
23.02.2022,namey,surenamey,test2@hotmail.com,Make a Purchase,0,
"""

df.at[previous_purchase_index, 'date_created']).days <= 366:
previous_purchase_index = None
previous_expire_date = None
for i in range(len(df)):
        if df.at[i, 'description'] == 'Make a Purchase':
            current_date = df.at[i, 'date_created']
        if previous_purchase_index is not None and (current_date - 
     df.at[previous_purchase_index, 'date_created']).days <= 366:

                df.at[i, 'expire_date'] = previous_expire_date
            else:
                
                df.at[i, 'expire_date'] = current_date + pd.DateOffset(days=366)
 previous_purchase_index = i           
 previous_expire_date = df.at[i, 'expire_date'] 

Upvotes: 0

Views: 53

Answers (0)

Related Questions