0
$\begingroup$

I have a scenario in which I'm required to run my analysis at the Account level. One of the features that I'd like to look at is the no. of subscriptions against an account. There can be multiple subscriptions against one account. I wonder how I can "aggregate" these multiple subscriptions and roll them up at the Account level, such that I have a single row for each account.

I could think of binary encoding but I have 5000 products and that would require creating these many features.

$\endgroup$
3
  • 2
    $\begingroup$ What tool or software or language are you using? Aggregating the number of subscriptions is done using some sort of groupby feature. As for the rest, what do mean by model and what are you using to construct your model? $\endgroup$ – fswings Sep 22 '19 at 14:50
  • $\begingroup$ In R, the function aggregate will do this. $\endgroup$ – G5W Sep 22 '19 at 16:42
  • $\begingroup$ I think what I'm asking is that if there are multiple products against an account(after group by and everything) in my analytical dataset, is there a way I could aggregate them in a single row. So that in my final dataset I have one row per account, but only this time with all product information. As I said, one way could be to create as many variables and mark them 1 if that product is included and 0 otherwise. But, I have huge number of features, so it seems not feasible. $\endgroup$ – Ahsan Sep 22 '19 at 16:43
1
$\begingroup$

You can use pandas groupby function to group your rows according to accounts and then perform your desired operation on them.

$\endgroup$
0
$\begingroup$

For one account, you can get all the products using a simple group by operation. Further, what you can do is create a vector having size as the no. of products and then populate that vector based on whether that product belongs to that account or not. For example if you have 5 products total, say P, Q, R, S, T and for account A, you have products P, R and T, then your vector for account A should be [1,0,1,0,1]. This way for each account you can get 1 row

$\endgroup$
3
  • $\begingroup$ So, that vector will add 5 extra columns to my dataset? $\endgroup$ – Ahsan Sep 22 '19 at 18:57
  • $\begingroup$ Yes, that’s correct $\endgroup$ – Gyan Ranjan Sep 22 '19 at 18:59
  • 1
    $\begingroup$ I think I mentioned this in the original question that I have 5000 products and binary encoding would require as many variables. What I am looking for is some other method that could handle such a large number of variables. $\endgroup$ – Ahsan Sep 22 '19 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.