I have the follwing dataframe:
Item | Type | Value |
---|---|---|
item1 | A1 | 11 |
item1 | A1 | 12 |
item2 | A1 | 21 |
item2 | A1 | 22 |
item3 | A1 | 31 |
item3 | A1 | 11 |
item4 | A1 | 12 |
item4 | A1 | 21 |
item5 | A2 | 22 |
item5 | A2 | 31 |
how can I count the unique occurrence of each item when the type=A1? in the above example, it should be 4
I was thinking of something like this:
df['Type']=='A1'
list=df['Item'].unique()
occurance=list.str.len()
is there a better and easier way to do that?