Simple Tree pruning in python.

Job ID: 32167014

Budget: $30 – $250 USD

Assignment Description:
Write the following Python program.
Input:
(1) Data Frame 1 (df1): consists of columns 'id' and 'parent id. The df1 represents products' tree where:
on the lowest level (all leaves) are products
on higher levels (all nodes) are product's categories
One record of the table df1 represents the inclusion of one category into another or a product into a category.
(2) Data Frame 2 (df2): consists of column 'id'. plus some additional columns. df2 - represents transactions (product id plus transaction description). Additional columns should be omitted; we only need to calculate from df2 how often a particular id appear in df2.
(2) Parameter L: representing a 'minimal number of products in the leaves'
Value in Data Frames are integers (products and categories names were mapped into numbers).

Task:
(1) Write a function that creates the Tree representation as a dictionary.
We should have categories as nodes and leaves as the 'id'. To every 'id' is assigned a number F (frequency) representing how often 'id' appears in df2. To every category is assigned a number representing the appearance of all 'id' included in that category (this is equal to the sum of all children frequencies).
(2) Based on the above Tree representation, write a function that prunes the tree according to the parameter L.
The functions must work for a large number of transactions and inconsistent data. In the latter case, the function must produce an appropriate warning.
The functions must give an output (it could be an error message) if the are two Python Data Frames and the parameter in the input.
Code must be in Python 3.
Related categories: Python Pandas