Count occurences of rows based one cell content with pandas I am currently struggling with the pandas framework.
Let's imagine the following Data Frame:
customer | order_number | product 
------------------------------------
A        | O1           | Product_1
A        | O1           | Product_2
A        | O2           | Product_X
B        | O5           | Product_1
C        | O6           | Product_2
C        | 06           | Product_X

What I am trying to do is to count the occurences of &quot;products&quot; based on &quot;order_number&quot;. This means that I would like to know how how often e.g. Product_1 and Product_2 were sold within one order. Of course I am interested in every available combination of products. I tried to use df.groupby['order_number'].count() but this is certainly not the data I want. At this point I am not interested in order_numbers nor the customers! Just the available sets of products and how often they appear within the data frame.
Thanks in advance!
Update: Based on my example this explains what I would like to get
Product_1 &amp;&amp; Product_2 | One Time
Product_X | One Time
Product_1 | One Time
Product_2 &amp;&amp; Product_X | One Time
When asking code related questions, its always a good practice to at least provide a sample of the data. Since, you've not given one, I'll create it based on your question.
import pandas as pd

df = pd.DataFrame([('A','01','prod_1'), 
                   ('A','01', 'prod_2'), 
                   ('A','02','prod_X'), 
                   ('B','05','prod_1'),
                   ('C','06','prod_2'),
                   ('C','06','prod_X')], 
                 columns=['customer', 'ordernum', 'product'])
print (df)
        customer ordernum product
0        A       01  prod_1
1        A       01  prod_2
2        A       02  prod_X
3        B       05  prod_1
4        C       06  prod_2
5        C       06  prod_X

Now, you can use size() or Counter like,
val_count = df.groupby(['product','ordernum']).size()
print(val_count)
product  ordernum
prod_1   01          1
         05          1
prod_2   01          1
         06          1
prod_X   02          1
         06          1
dtype: int64

prod_order_count = df.groupby(['product', 'ordernum']).agg(Counter)
print(prod_order_count)
                  customer
product ordernum          
prod_1  01        {'A': 1}
        05        {'B': 1}
prod_2  01        {'A': 1}
        06        {'C': 1}
prod_X  02        {'A': 1}
        06        {'C': 1}