0

I have a DF that I'd like to create a tree structure with. My spreadsheet looks like this:

Regional Exposure.750013 | Not Classified.18500016 | Country Exposure (Equity).750015 | Country Exposure (Equity) to Yugoslavia.18750254

Regional Exposure.750013 | Africa.18500008 | Country Exposure (Equity).750015 | Country Exposure (Equity) to South Africa.18750255

Regional Exposure.750013 | Africa.18500008 | Country Exposure (Equity).750015 | Country Exposure (Equity) to Zambia.18750256

Regional Exposure.750013 | Africa.18500008 | Country Exposure (Equity).750015 | Country Exposure (Equity) to Zaire.18750257

... and so on.

I've been able to create a class hierarchy using super(). I'd like to create a diamond tree structure that incorporates left to right parent to child node relationships. For example, in row one, A is the parent of B, B is the parent of C, C is the parent of D.

Does anyone know how to use the LoggingDict to create the tree structure for the whole dataframe? (30,000+ rows)

Thanks, Nazar

EDIT: We're trying to rebuild this tree that was not created correctly as an array. We've been able to create the super class but having trouble plotting it on a graph

our code for creating the dictionary:

import collections
import logging

logging.basicConfig(level='INFO')




class LoggingDict(dict):
    def __setitem__(self, key, value): 
        class LoggingOD(LoggingDict, collections.OrderedDict):
            pass

import pandas as pd
bdh=pd.read_csv('C:\\Users\\nkurdob\\Documents\\bdh2.csv')
ld = LoggingDict(bdh)

We're hoping to use GraphViz to plot these relationships as a tree. We may not have needed to create a superclass.

Window
  • 87
  • 1
  • 8

0 Answers0