Package: taxonomy4good
Taxonomy4GoodGood Data Hub empowers impact-driven data scientists with simple tools that provide the highest quality of data and reporting.Analysis of unstructured sustainability data is arduous, time-consuming, and expensive. 
Our goal is to reduce the barriers to accessing, processing, and analyzing sustainability data by providing an open-source sustainability lexicon. We are committed to developing tools that enhance the efficiency and practicality of working with such data.Taxonomy4good is the first open-source library for ESG and Sustainability standards and taxonomies.Organizations that trust usWhat are Taxonomies?Taxonomy is the practice and science of categorization or classification. A taxonomy (or taxonomical classification) is a scheme of classification, specifically a hierarchical categorization and organization of data into distinct classes or groups based on shared characteristics.Taxonomy4GoodTaxonomy4good is the first and only centralized repository for Sustainability and ESG standards in code form, ready for data labeling and for use with an API to query relevant data. These data structures can also be leveraged in ML and NLP for ESG/Sustainability reporting and data processing. Users can seamlessly integrate the provided taxonomies into their workflow, or create a custom taxonomy to form a reporting structure for existing sustainability scoring models.Use CasesUse with an APIData TaggingML and Topic ModelingSupervised aspect based sentiment analysisText classificationKeyword extractionInstallationpip install taxonomy4goodQuick TourUse existing taxonomyTo use an existing taxonomy, e.g.ftse_fsgi, you can import it directly as follows.fromtaxonomy4goodimportfrom_fileftse_builtin_taxonomy=from_file("ftse_fsgi")Available Taxonomies:NameDescriptionun_sdg_taxonomyUN Sustainabile Development Goalseu_taxonomyEuropean Union Taxonomyftse_fsgiFTSE for Social Good Indexworld_bank_taxonomyWorld Bank taxonomychina_taxonomyChina Taxonomyesg_taxonomyESG standard taxonomyen_master_lexiconStructure of the entire sustainability lexiconCreate custom taxonomyCreate a custom taxonomy from scratch usingSustainabilityItemobjects, then initialize one of the items
as a root item to a newly createdSustainabilityTaxonomy.fromtaxonomy4goodimportSustainabilityTaxonomy,SustainabilityItemroot=SustainabilityItem(id=0,name="New Taxonomy")item1=SustainabilityItem(id=1,name="item1",parent=root)item2=SustainabilityItem(id=2,name="item2",parent=root)item3=SustainabilityItem(id=3,name="item3",parent=item1)item4=SustainabilityItem(id=4,name="item4",parent=item1)item5=SustainabilityItem(id=5,name="item5",parent=item2)item6=SustainabilityItem(id=6,name="item6",parent=item2)root.children=[item1,item2]item1.children=[item3,item4]item2.children=[item5,item6]custom_taxonomy=SustainabilityTaxonomy(root,version_name="Custom Taxonomy")custom_taxonomy.print_hierarchy()See the resulting taxonomy as follows.>>> custom_taxonomy.print_hierarchy()
New Taxonomy : 0
│
│
├─────item1 : 0
│       └───── item3 : 0
│       └───── item4 : 0
└─────item2 : 0
        └───── item5 : 0
        └───── item6 : 0Get all items and termsTo get all the items and terms of the taxonomy use the following lines.# list of all SustainabilityItem objectsall_items=custom_taxonomy.get_items()# list of terms (item names)all_terms=custom_taxonomy.get_terms()The resulting terms are shown in the following snippet.>>> print(all_terms)
['New Taxonomy', 'item1', 'item2', 'item3', 'item4']Search termsSearch for terms by providing a substring. This can help get relevant terms fromen_full_taxonomy,
providing you with the most similar sustainability terms that will help query textual data from various APIs and extend
ML and NLP tasks.search_result=custom_taxonomy.search_items_by_name("item")resulting_terms=[result.nameforresultinsearch_result]The resulting terms are:>>> print(resulting_terms)
['item1', 'item2', 'item3', 'item4', 'item5', 'item6']Update and compute scoresScores and weights can be updated using an external API or imported from an Excel sheet with the taxonomy.
The following is an alternative way to update the scores programmatically# update scores and weights# scores and weights can be updated using an API or from Excelall_items[3].score=10all_items[3].weight=0.3all_items[4].score=23all_items[4].weight=0.7all_items[5].score=7.4all_items[5].weight=0.5all_items[6].score=-13all_items[6].weight=0.5# compute scoreroot_score=custom_taxonomy.compute_scores()Get the result of the updates in the following snippet.>>> print(root_score)

16.299999999999997

>>> custom_taxonomy.print_hierarchy()

New Taxonomy : 16.299999999999997
│
│
├─────item1 : 19.099999999999998
│       └───── item3 : 10
│       └───── item4 : 23
└─────item2 : -2.8
        └───── item5 : 7.4
        └───── item6 : -13Finding childrenroot_children=all_items[0].childrenroot_children_names=[child.nameforchildinroot_children]>>> print(root_children_names)
['item1', 'item2']Who is the parentitem_parent=all_items[1].parent>>> print(item_parent.name)
New TaxonomyImport your own taxonomyCeate your own taxonomy in Excel and make use of the provided data structureSustainabilityTaxonomy.
The items of this data structure must include the following columns (attributes):id,name,level,grouping,parent,score,weight,children. Any other columns will be aggregated inside a dictionary calledmeta_data.Feel free to enrich your taxonomy with additional attributes!The following is an example Excel file that is filled manually to provide a custom taxonomy.The columnsAcronym,Col 1, andCol 2will be included in the attributemeta_dataof the resultingSustainabilityTaxonomyobject, as shown below.fromtaxonomy4goodimportfrom_fileexample=from_file("examples/taxonomy example.xlsx",filetype="excel",meta=True)The resulting taxonomy can be printed as follows.>>> example.print_hierarchy()
Standard Taxonomy : 0
│
│
├─────Environment : 0
│       └───── Air quality : 0
│              └───── Air pollution : 0
│              └───── Ozone layer : 0
│       └───── Climate impacts : 0
│              └───── United Nations Climate Change Conference : 0
│              └───── Climate Change : 0
│              └───── Sustainability Accounting Standards Board : 0
│              └───── COP26 : 0
│       └───── Ecosystem Impacts : 0
│              └───── Flood Damage : 0
│              └───── Ecosystem Conservation : 0
└─────Social : 0
        └───── Product Quality and Safety : 0
               └───── Access/Affordability : 0
               └───── Product Recall : 0
               └───── Quality Control : 0
               └───── Product Safety : 0
               └───── Customer Satisfaction : 0
        └───── Stakeholder relations : 0
               └───── Charity : 0
               └───── Donations : 0
               └───── Community Outreach : 0To check the attributes of an item search for the item byidor bynameas follows.social_item=example.search_items_by_name("Social")[0]orsocial_item=example.search_by_id(13)[0]Printing the details of a certainSustainabilityItemobject works as follows.>>> social_item.details()
name: Social
id: 13
level: 1
children: [14, 20]
parent: 0
score: 0
weight: 1
meta_data: {'Acronym': None, 'Col 1': None, 'Col 2': None}Note howmeta_datastored the additional columns introduced in the Excel file.Overview of all functionsFunctionDescriptioninsert_items(items)Insert additional items (terms/lexicons) to this existing taxonomyremove_subtree(items)Remove the passed items along with their children from the taxonomyremove_by_id(ids)Remove from the taxonomy items corresponding to the supplied idsget_items_each_level(start_root)Get lists of items for each level of the taxonomy (grouped by level)get_level_items(level)Get items of the specified levelget_items(start_root)Get all the items of the structureget_terms(start_root)Get all terms (names/lexicon) in the taxonomyget_all_ids(start_root)Get ids of all the nodes in the current taxonomy (grouped by level)search_by_id(ids)Search for items by their idlevel(start_item)Compute the maximum depth/level of the taxonomyto_csv(filepath, start_root)Save current taxonomy/substructure to a csv fileto_excel(filepath, start_root)Save current taxonomy/substructure to an Excel fileitems_to_json(filepath, start_root)Save current taxonomy/substructure items to a JSON file (records structure)taxonomy_to_json(filepath, start_root)Save current taxonomy/substructure items to a JSON file (hierarchical structure)print_hierarchy(start_item, current_level, islast)Print the current hierarchy of the taxonomy with the respective valuesget_level_scores(level)Compute the weighted values/scores for the specified levelcompute_scores(start_root, root_score)Compute the weighted scores for the entire taxonomysummary()Print the general information about the entire taxonomyto_dataframe(start_root)Convert the entire taxonomy to a DataFramesimilar_items(sustainability_items)Gives the items under the same parentsimilar_items_byid(ids)Gives the items under the same parent as items having the specified idssearch_items_by_name(terms, start_root)Look for similar SustainabilityItems using a string partial matchsearch_similar_names(terms, start_root)Search for similar names/terms in the taxonomy using a string partial matchitems_to_dict(start_root)Convert the entire taxonomy to a list of dictionaries (records) starting from start_roottaxonomy_to_dict(start_root)Convert the entire taxonomy to a dictionary (structural hierarchy) starting from start_rootCommunityJoin Good Data Hub's community of sustainability data scientists and ML enthusiasts.🌟 Leave a star on ourGitHub.🐞 Report bugs withGitHub Issues.🔗 Follow us onLinkedin.