Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the table below is dataset, There are 4 columns and first 14 rows of the dataset is given but there are over 10,000 rows.

Given the table below is dataset, There are 4 columns and first 14 rows of the dataset is given but there are over 10,000 rows. In a order there are multiple products being sold to a client from different industry

I want to find out, How frequency of product pair orders vary accross industry

In other words, I want the pairs that appear the most accross all orders and by industry. For example in Order 4997 (Cat 1, Cat 2, IT) - 1 (Cat 2, Cat 3, IT) - 1 and (Cat 1, Cat 3, IT ) - 1. In order 2001, (Cat 1, Cat 2, Real estate) - 1 (Cat1, Cat 3, Real estate) - 1 (Cat 2, Cat 3, Real estate) - 1 appear once In total, I want to get frequency of all order pairs based on the industry

Note - there are only 3 categories and product ID is unique column, Order ID and Industry has 3 unique values i.e IT, finance and Real estate

OrderID ProdID Prodcategory Client ID 4997 1 Cat 1 IT 4997 2 Cat 1 IT 4997 3 Cat 2 IT 4997 4 Cat 3 IT 2001 5 Cat 1 Real Est 2001 6 Cat 2 Real Est 2001 7 Cat 2 Real Est 2001 8 Cat 2 Real Est 2001 9 Cat 3 Real Est 2376 10 Cat 3 Finace 2376 11 Cat 1 Finance 2376 12 Cat 2 Finance 2376 13 Cat 3 Finance 2376 14 Cat 1 Finance

MY approach ``` from itertools import combinations cats=df.groupby('OrderID')['Prodcategory']\ .agg(list)\ .apply(lambda x:list(combinations(set(x),2)))\ .explode()

cats OrderID 2001 (Cat2, Cat1) 2001 (Cat2, Cat3) 2001 (Cat1, Cat3) 2376 (Cat2, Cat1) 2376 (Cat2, Cat3) 2376 (Cat1, Cat3) 4997 (Cat2, Cat1) 4997 (Cat2, Cat3) 4997 (Cat1, Cat3)

cats.value_counts()

(Cat2, Cat3) 3 (Cat1, Cat3) 3 (Cat2, Cat1) 3 ```

this gives me count of category pairs accross all orders, I have to include Industry in this code too but I am confused how to.

Expected output is something like

(Cat2, Cat3) IT 10 (Cat2, Cat3) real estate 5 (Cat1, Cat3) finance 2 (Cat2, Cat1) It 3

and so on

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial and managerial accounting

Authors: Jerry J. Weygandt, Paul D. Kimmel, Donald E. Kieso

1st edition

111800423X, 9781118233443, 1118016114, 9781118004234, 1118233441, 978-1118016114

More Books

Students also viewed these Accounting questions

Question

What is the standard for successful learning?

Answered: 1 week ago