is there a way in python to infer order in repeating values ? I.e What is the most commun order people who buy more than one item purchase?

Viewed 52

I am trying to figure out the most frequent order purchases are made.

I have the following table:

    Client Id       Acc      product           cycle
0   0001-0000-0076  24666   Solar lamp          6.0
1   0001-0000-0076  34859   Canvas grain        7.0
2   0001-0000-0111  24667   LPG cylinder        2.0
3   0001-0000-0111  37108   Canvas grain        3.0
4   0001-0000-0326  23195   Solar radio lamp    4.0
5   0001-0000-0326  37687   Solar lamp          5.0
6   0001-0000-0381  22724   LPG cylinder        3.0
7   0001-0000-0381  34891   Solar radio lamp    4.0
8   0001-0000-0920  35057   Canvas grain        4.0
9   0001-0000-0920  21529   Solar lamp          3.0

In which cycle indicates if its the 1st purchase of that person (cycle = 1.0) or 4th (cycle = 4.0).

I did it like this :

sort.groupby(['product','cycle']).size().nlargest(10).sort_values(ascending=False)

got this output:

product           cycle
LPG cylinder      1.0      333
                  2.0      171
Canvas grain      2.0      160
Charcoal Stove    1.0      109
                  2.0      104
Solar lamp        2.0       86
Gas cooker        2.0       66
Solar lamp        1.0       52
Canvas grain      3.0       46
Solar radio lamp  2.0       38
dtype: int64

Am I correct?

0 Answers
Related