0

Dataframe df

  cust_id   order_date    
    1       2015-01-16      
    1       2019-12-03      
    2       2014-12-21      
    2       2015-01-10      
    1       2015-01-10
    3       2018-01-18
    3       2017-03-04
    4       2019-11-05
    4       2010-01-01
    3       2019-12-06
    3       2002-01-01
    3       2018-01-01

Active function will find out customers who have transacted in the past one month and have bought at least 3 times from a site.

 def active(month_before_current_month, freq):
         df['Frequency'] = df.groupby('cust_id')['order_date'].nunique()
         df = df.groupby('customer_id')['order_date'].max().loc[lambda x:x>= 
         (datetime.date.today() - 

          datetime.timedelta(month_before_current_month*365/12))].loc[lambda 
            x: 
             x['Frequency']>=3].reset_index().rename(columns= 
            {'order_date':'Most_recent_date'})
         return df

Output of active(1,3) function will be:(people who have bought 1 month before and have made at least 3 transactions till date)

    cust_id   Most_recent_date Frequency
     1         2019-12-03        3
     3          2019-12-06       5

Now I want to create another function which uses the function active to see after how much time we should send out fliers or marketing ads etc to these customers.

   def active_target(month_before_current_month, freq):
      df=active(month_before_current_month,freq)
      return df['Frequency'].mean()

This works fine. However I would like to pass the arguments active function itself.

When I do this:

       def active_target(**kwargs):
           df=active(month_before_current_month,freq)
           return df['Frequency'].mean()

Calling active_target

      active_target(active(1,freq))
          **I am getting error TypeError: active_target() takes 0 positional 
          arguments but 1 was given**

Can anyone help:

noob
  • 3,601
  • 6
  • 27
  • 73

0 Answers0