Skip to content

Instantly share code, notes, and snippets.

@firmai
Last active February 12, 2024 11:15
Show Gist options
  • Save firmai/19351348ade55252267bf5bbf565b540 to your computer and use it in GitHub Desktop.
Save firmai/19351348ade55252267bf5bbf565b540 to your computer and use it in GitHub Desktop.
FinML MSCI Ranking.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "FinML MSCI Ranking.ipynb",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/firmai/19351348ade55252267bf5bbf565b540/finml-msci-ranking.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"Install required scraping libraries (can take 5 minutes)"
],
"metadata": {
"id": "0VmLvt9Vb86j"
}
},
{
"cell_type": "code",
"metadata": {
"id": "owzSKGvkdCBQ"
},
"source": [
"%%capture\n",
"!pip install selenium\n",
"!pip install py-msci-esg"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "TvXspcihcE41"
},
"source": [
"%%capture\n",
"!wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2\n",
"!tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2\n",
"!cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin\n",
"!ls -al"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Scrape for S&P Constituents and Grab Wikipedia Page"
],
"metadata": {
"id": "9kB8MQqWj8T1"
}
},
{
"cell_type": "code",
"source": [
"import pandas as pd\n",
"import html5lib\n",
"from bs4 import BeautifulSoup\n",
"import requests\n",
"# Scrape the entire S&P500 list from Wikipedia into a Pandas DataFrame;\n",
"ticker_list = pd.read_html(\n",
"'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')\n",
"df = ticker_list[0]\n",
"# Drop a few unwanted columns of data;\n",
"# df.drop(columns = ['SEC filings', 'Date first added', 'Founded'], inplace = True)\n",
"# Fill out CIK codes by converting to string then adding in 0's up to 10 digits.\n",
"df.CIK = df.CIK.astype(str)\n",
"df['CIK'] = df['CIK'].str.zfill(10)\n",
"request = requests.get(\n",
"'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')\n",
"df['WIKI_URL'] = ''\n",
"soup = BeautifulSoup(request.content)\n",
"main_table = soup.find(id='constituents')\n",
"table = main_table.find('tbody').findAll('tr')\n",
"table = table[1:]\n",
"base_url = 'https://en.wikipedia.org'\n",
"url_list = []\n",
"for item in table:\n",
" url = base_url + str(item.findAll('a')[1]['href'])\n",
" url_list.append(url)\n",
"\n",
"df['WIKI_URL'] = url_list\n",
"df = df[df[\"Symbol\"]!=\"POOL\"].reset_index(drop=True)\n",
"df.tail()\n",
"df[\"Search\"] = df[\"WIKI_URL\"].str.split(\"https://en.wikipedia.org/wiki/\").apply(lambda x: x[1])\n",
"import json\n",
"apps = []\n",
"\n",
"for name in df[\"Search\"].to_list():\n",
" r = requests.get(\"https://en.wikipedia.org/w/api.php?action=query&format=json&titles=\"+name+\"&redirects\", allow_redirects=False)\n",
" data = json.loads(r.text)\n",
" try:\n",
" dal = data[\"query\"][\"redirects\"][0][\"to\"]\n",
" except:\n",
" try:\n",
" dal = data[\"query\"][\"normalized\"][0][\"to\"]\n",
" except:\n",
" dal = name\n",
" apps.append(dal)\n",
"df[\"clean_search\"] = apps"
],
"metadata": {
"id": "_yQo3QlvlFHt"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df.head(5)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 409
},
"id": "eLrCVbbymFOM",
"outputId": "9bae1459-e4db-4ca5-c466-dd4aab64e60a"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Symbol Security GICS Sector GICS Sub-Industry \\\n",
"0 MMM 3M Industrials Industrial Conglomerates \n",
"1 AOS A. O. Smith Industrials Building Products \n",
"2 ABT Abbott Health Care Health Care Equipment \n",
"3 ABBV AbbVie Health Care Pharmaceuticals \n",
"4 ACN Accenture Information Technology IT Consulting & Other Services \n",
"\n",
" Headquarters Location Date added CIK Founded \\\n",
"0 Saint Paul, Minnesota 1976-08-09 0000066740 1902 \n",
"1 Milwaukee, Wisconsin 2017-07-26 0000091142 1916 \n",
"2 North Chicago, Illinois 1964-03-31 0000001800 1888 \n",
"3 North Chicago, Illinois 2012-12-31 0001551152 2013 (1888) \n",
"4 Dublin, Ireland 2011-07-06 0001467373 1989 \n",
"\n",
" WIKI_URL Search \\\n",
"0 https://en.wikipedia.org/wiki/3M 3M \n",
"1 https://en.wikipedia.org/wiki/A._O._Smith A._O._Smith \n",
"2 https://en.wikipedia.org/wiki/Abbott_Laboratories Abbott_Laboratories \n",
"3 https://en.wikipedia.org/wiki/AbbVie AbbVie \n",
"4 https://en.wikipedia.org/wiki/Accenture Accenture \n",
"\n",
" clean_search \n",
"0 3M \n",
"1 A. O. Smith \n",
"2 Abbott Laboratories \n",
"3 AbbVie \n",
"4 Accenture "
],
"text/html": [
"\n",
" <div id=\"df-284fc813-7725-436c-bd7b-aae98ffde26e\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Symbol</th>\n",
" <th>Security</th>\n",
" <th>GICS Sector</th>\n",
" <th>GICS Sub-Industry</th>\n",
" <th>Headquarters Location</th>\n",
" <th>Date added</th>\n",
" <th>CIK</th>\n",
" <th>Founded</th>\n",
" <th>WIKI_URL</th>\n",
" <th>Search</th>\n",
" <th>clean_search</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>MMM</td>\n",
" <td>3M</td>\n",
" <td>Industrials</td>\n",
" <td>Industrial Conglomerates</td>\n",
" <td>Saint Paul, Minnesota</td>\n",
" <td>1976-08-09</td>\n",
" <td>0000066740</td>\n",
" <td>1902</td>\n",
" <td>https://en.wikipedia.org/wiki/3M</td>\n",
" <td>3M</td>\n",
" <td>3M</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>AOS</td>\n",
" <td>A. O. Smith</td>\n",
" <td>Industrials</td>\n",
" <td>Building Products</td>\n",
" <td>Milwaukee, Wisconsin</td>\n",
" <td>2017-07-26</td>\n",
" <td>0000091142</td>\n",
" <td>1916</td>\n",
" <td>https://en.wikipedia.org/wiki/A._O._Smith</td>\n",
" <td>A._O._Smith</td>\n",
" <td>A. O. Smith</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>ABT</td>\n",
" <td>Abbott</td>\n",
" <td>Health Care</td>\n",
" <td>Health Care Equipment</td>\n",
" <td>North Chicago, Illinois</td>\n",
" <td>1964-03-31</td>\n",
" <td>0000001800</td>\n",
" <td>1888</td>\n",
" <td>https://en.wikipedia.org/wiki/Abbott_Laboratories</td>\n",
" <td>Abbott_Laboratories</td>\n",
" <td>Abbott Laboratories</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>ABBV</td>\n",
" <td>AbbVie</td>\n",
" <td>Health Care</td>\n",
" <td>Pharmaceuticals</td>\n",
" <td>North Chicago, Illinois</td>\n",
" <td>2012-12-31</td>\n",
" <td>0001551152</td>\n",
" <td>2013 (1888)</td>\n",
" <td>https://en.wikipedia.org/wiki/AbbVie</td>\n",
" <td>AbbVie</td>\n",
" <td>AbbVie</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>ACN</td>\n",
" <td>Accenture</td>\n",
" <td>Information Technology</td>\n",
" <td>IT Consulting &amp; Other Services</td>\n",
" <td>Dublin, Ireland</td>\n",
" <td>2011-07-06</td>\n",
" <td>0001467373</td>\n",
" <td>1989</td>\n",
" <td>https://en.wikipedia.org/wiki/Accenture</td>\n",
" <td>Accenture</td>\n",
" <td>Accenture</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-284fc813-7725-436c-bd7b-aae98ffde26e')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-284fc813-7725-436c-bd7b-aae98ffde26e button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-284fc813-7725-436c-bd7b-aae98ffde26e');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 8
}
]
},
{
"cell_type": "markdown",
"source": [
"Now we want to use a pre-built scraper to grab the appropriate data on the MSCI website. To learn more about the scraper you can go and visit [this](https://github.com/austinjhunt/msci_esg/blob/master/msci_esg/ratefinder.py) python repository. This scraper package broke, this is a normal part of coding, let's ignore this part, and go straight to the data from an earlier export below."
],
"metadata": {
"id": "uRN9IPv1mNee"
}
},
{
"cell_type": "code",
"metadata": {
"id": "1FB66Krfa_fd",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 236
},
"outputId": "b063ea20-4ca8-4e13-8056-1610ecc0daab"
},
"source": [
"## SCRAPER doesn't work perfectly (few scrapers do), move on to data section\n",
"from msci_esg.ratefinder import ESGRateFinder\n",
"import pandas as pd\n",
"from selenium import webdriver\n",
"\n",
"driver = webdriver.PhantomJS('phantomjs')\n",
"\n",
"# Create an ESGRateFinder object, optionally passing in debug=True for more print statements\n",
"ratefinder = ESGRateFinder()\n",
"\n",
"# Call the ratefinder object's get_esg_rating method, passing in the Apple stock symbol and\n",
"# a JS timeout of 5 seconds (this is how long the Selenium web driver should wait for JS to execute\n",
"# before scraping content)\n",
"\n",
"rep_full = {}\n",
"for tick in df[\"Symbol\"].head(15).to_list():\n",
" try:\n",
" response = ratefinder.get_esg_rating(\n",
" symbol=tick,\n",
" js_timeout=5\n",
" )\n",
" rep_full[tick]=response\n",
" print(\"success \"+tick)\n",
" except:\n",
" print(\"fail \"+tick)\n",
" continue"
],
"execution_count": null,
"outputs": [
{
"output_type": "error",
"ename": "AttributeError",
"evalue": "ignored",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-9-7fbf7360225c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mselenium\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mwebdriver\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mdriver\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mwebdriver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPhantomJS\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'phantomjs'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;31m# Create an ESGRateFinder object, optionally passing in debug=True for more print statements\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: module 'selenium.webdriver' has no attribute 'PhantomJS'"
]
}
]
},
{
"cell_type": "code",
"source": [
"!wget https://storage.googleapis.com/public-quant/course//content/rep_full.p"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "6VIrWhWAnyaW",
"outputId": "9fdf6da7-86bd-4a47-ff83-202b43b8e59e"
},
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"--2024-02-12 11:15:06-- https://storage.googleapis.com/public-quant/course//content/rep_full.p\n",
"Resolving storage.googleapis.com (storage.googleapis.com)... 173.194.211.207, 173.194.212.207, 173.194.213.207, ...\n",
"Connecting to storage.googleapis.com (storage.googleapis.com)|173.194.211.207|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 108374 (106K) [application/octet-stream]\n",
"Saving to: ‘rep_full.p’\n",
"\n",
"rep_full.p 100%[===================>] 105.83K --.-KB/s in 0.001s \n",
"\n",
"2024-02-12 11:15:07 (92.1 MB/s) - ‘rep_full.p’ saved [108374/108374]\n",
"\n"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "LlJ63QrPiF-V"
},
"source": [
"import pickle\n",
"import pandas as pd\n",
"\n",
"rep_full = pickle.load(open(\"rep_full.p\", \"rb\"))\n",
"df = pd.DataFrame.from_dict(rep_full)"
],
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df.shape"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "nm2XU76EdTQl",
"outputId": "cef87dc5-ea1b-44ee-b70f-8f113a6ed91d"
},
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(4, 505)"
]
},
"metadata": {},
"execution_count": 3
}
]
},
{
"cell_type": "code",
"source": [
"df.head()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 450
},
"id": "Jq32daV8n4tV",
"outputId": "d81ea2ed-4676-4c9b-a0f1-fb8eeef7c3b7"
},
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" MMM \\\n",
"rating-paragraph 3M is a leader among 36 companies in the indus... \n",
"rating-history-paragraph 3M's rating remains unchanged since August, 2017. \n",
"current {'esg_rating': 'aaa', 'esg_category': 'leader'} \n",
"history {'sep-16': 'aaa', 'aug-17': 'aaa', 'aug-18': '... \n",
"\n",
" AOS \\\n",
"rating-paragraph A. O. Smith is average among 24 companies in t... \n",
"rating-history-paragraph A. O. Smith's rating remains unchanged since F... \n",
"current {'esg_rating': 'bbb', 'esg_category': 'average'} \n",
"history {'feb-17': 'bbb', 'feb-18': 'bb', 'feb-19': 'b... \n",
"\n",
" ABT \\\n",
"rating-paragraph NaN \n",
"rating-history-paragraph NaN \n",
"current NaN \n",
"history NaN \n",
"\n",
" ABBV \\\n",
"rating-paragraph AbbVie is average among 39 companies in the bi... \n",
"rating-history-paragraph AbbVie's rating remains unchanged since Octobe... \n",
"current {'esg_rating': 'a', 'esg_category': 'average'} \n",
"history {'oct-16': 'bbb', 'oct-17': 'bbb', 'oct-18': '... \n",
"\n",
" ACN \\\n",
"rating-paragraph Accenture is average among 143 companies in th... \n",
"rating-history-paragraph Accenture was downgraded in December, 2020. \n",
"current {'esg_rating': 'a', 'esg_category': 'average'} \n",
"history {'jun-17': 'aaa', 'jun-18': 'aaa', 'mar-19': '... \n",
"\n",
" ATVI AYI ADBE AAP AMD ... WYNN XEL XRX XLNX \\\n",
"rating-paragraph NaN NaN NaN NaN NaN ... NaN NaN NaN NaN \n",
"rating-history-paragraph NaN NaN NaN NaN NaN ... NaN NaN NaN NaN \n",
"current NaN NaN NaN NaN NaN ... NaN NaN NaN NaN \n",
"history NaN NaN NaN NaN NaN ... NaN NaN NaN NaN \n",
"\n",
" XL \\\n",
"rating-paragraph NaN \n",
"rating-history-paragraph NaN \n",
"current NaN \n",
"history NaN \n",
"\n",
" XYL \\\n",
"rating-paragraph XYLEM is a leader among 51 companies in the in... \n",
"rating-history-paragraph XYLEM's rating remains unchanged since Februar... \n",
"current {'esg_rating': 'aaa', 'esg_category': 'leader'} \n",
"history {'feb-17': 'aa', 'feb-18': 'aa', 'feb-19': 'aa... \n",
"\n",
" YUM \\\n",
"rating-paragraph NaN \n",
"rating-history-paragraph NaN \n",
"current NaN \n",
"history NaN \n",
"\n",
" ZBH \\\n",
"rating-paragraph Zimmer Biomet is a laggard among 93 companies ... \n",
"rating-history-paragraph Zimmer Biomet was upgraded in May, 2020. \n",
"current {'esg_rating': 'b', 'esg_category': 'laggard'} \n",
"history {'dec-16': 'ccc', 'dec-17': 'ccc', 'dec-18': '... \n",
"\n",
" ZION \\\n",
"rating-paragraph NaN \n",
"rating-history-paragraph NaN \n",
"current NaN \n",
"history NaN \n",
"\n",
" ZTS \n",
"rating-paragraph Zoetis is a leader among 99 companies in the p... \n",
"rating-history-paragraph Zoetis was upgraded in March, 2021. \n",
"current {'esg_rating': 'aa', 'esg_category': 'leader'} \n",
"history {'sep-17': 'aa', 'dec-18': 'a', 'jun-19': 'a',... \n",
"\n",
"[4 rows x 505 columns]"
],
"text/html": [
"\n",
" <div id=\"df-79150747-ace2-4334-868a-508801a530fb\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>MMM</th>\n",
" <th>AOS</th>\n",
" <th>ABT</th>\n",
" <th>ABBV</th>\n",
" <th>ACN</th>\n",
" <th>ATVI</th>\n",
" <th>AYI</th>\n",
" <th>ADBE</th>\n",
" <th>AAP</th>\n",
" <th>AMD</th>\n",
" <th>...</th>\n",
" <th>WYNN</th>\n",
" <th>XEL</th>\n",
" <th>XRX</th>\n",
" <th>XLNX</th>\n",
" <th>XL</th>\n",
" <th>XYL</th>\n",
" <th>YUM</th>\n",
" <th>ZBH</th>\n",
" <th>ZION</th>\n",
" <th>ZTS</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>rating-paragraph</th>\n",
" <td>3M is a leader among 36 companies in the indus...</td>\n",
" <td>A. O. Smith is average among 24 companies in t...</td>\n",
" <td>NaN</td>\n",
" <td>AbbVie is average among 39 companies in the bi...</td>\n",
" <td>Accenture is average among 143 companies in th...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>XYLEM is a leader among 51 companies in the in...</td>\n",
" <td>NaN</td>\n",
" <td>Zimmer Biomet is a laggard among 93 companies ...</td>\n",
" <td>NaN</td>\n",
" <td>Zoetis is a leader among 99 companies in the p...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>rating-history-paragraph</th>\n",
" <td>3M's rating remains unchanged since August, 2017.</td>\n",
" <td>A. O. Smith's rating remains unchanged since F...</td>\n",
" <td>NaN</td>\n",
" <td>AbbVie's rating remains unchanged since Octobe...</td>\n",
" <td>Accenture was downgraded in December, 2020.</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>XYLEM's rating remains unchanged since Februar...</td>\n",
" <td>NaN</td>\n",
" <td>Zimmer Biomet was upgraded in May, 2020.</td>\n",
" <td>NaN</td>\n",
" <td>Zoetis was upgraded in March, 2021.</td>\n",
" </tr>\n",
" <tr>\n",
" <th>current</th>\n",
" <td>{'esg_rating': 'aaa', 'esg_category': 'leader'}</td>\n",
" <td>{'esg_rating': 'bbb', 'esg_category': 'average'}</td>\n",
" <td>NaN</td>\n",
" <td>{'esg_rating': 'a', 'esg_category': 'average'}</td>\n",
" <td>{'esg_rating': 'a', 'esg_category': 'average'}</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>{'esg_rating': 'aaa', 'esg_category': 'leader'}</td>\n",
" <td>NaN</td>\n",
" <td>{'esg_rating': 'b', 'esg_category': 'laggard'}</td>\n",
" <td>NaN</td>\n",
" <td>{'esg_rating': 'aa', 'esg_category': 'leader'}</td>\n",
" </tr>\n",
" <tr>\n",
" <th>history</th>\n",
" <td>{'sep-16': 'aaa', 'aug-17': 'aaa', 'aug-18': '...</td>\n",
" <td>{'feb-17': 'bbb', 'feb-18': 'bb', 'feb-19': 'b...</td>\n",
" <td>NaN</td>\n",
" <td>{'oct-16': 'bbb', 'oct-17': 'bbb', 'oct-18': '...</td>\n",
" <td>{'jun-17': 'aaa', 'jun-18': 'aaa', 'mar-19': '...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>{'feb-17': 'aa', 'feb-18': 'aa', 'feb-19': 'aa...</td>\n",
" <td>NaN</td>\n",
" <td>{'dec-16': 'ccc', 'dec-17': 'ccc', 'dec-18': '...</td>\n",
" <td>NaN</td>\n",
" <td>{'sep-17': 'aa', 'dec-18': 'a', 'jun-19': 'a',...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>4 rows × 505 columns</p>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-79150747-ace2-4334-868a-508801a530fb')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-79150747-ace2-4334-868a-508801a530fb button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-79150747-ace2-4334-868a-508801a530fb');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
"<div id=\"df-6bbc5ab8-700b-480a-8b42-cde2ec18e639\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-6bbc5ab8-700b-480a-8b42-cde2ec18e639')\"\n",
" title=\"Suggest charts\"\n",
" style=\"display:none;\">\n",
"\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <g>\n",
" <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
" </g>\n",
"</svg>\n",
" </button>\n",
"\n",
"<style>\n",
" .colab-df-quickchart {\n",
" --bg-color: #E8F0FE;\n",
" --fill-color: #1967D2;\n",
" --hover-bg-color: #E2EBFA;\n",
" --hover-fill-color: #174EA6;\n",
" --disabled-fill-color: #AAA;\n",
" --disabled-bg-color: #DDD;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-quickchart {\n",
" --bg-color: #3B4455;\n",
" --fill-color: #D2E3FC;\n",
" --hover-bg-color: #434B5C;\n",
" --hover-fill-color: #FFFFFF;\n",
" --disabled-bg-color: #3B4455;\n",
" --disabled-fill-color: #666;\n",
" }\n",
"\n",
" .colab-df-quickchart {\n",
" background-color: var(--bg-color);\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: var(--fill-color);\n",
" height: 32px;\n",
" padding: 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-quickchart:hover {\n",
" background-color: var(--hover-bg-color);\n",
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: var(--button-hover-fill-color);\n",
" }\n",
"\n",
" .colab-df-quickchart-complete:disabled,\n",
" .colab-df-quickchart-complete:disabled:hover {\n",
" background-color: var(--disabled-bg-color);\n",
" fill: var(--disabled-fill-color);\n",
" box-shadow: none;\n",
" }\n",
"\n",
" .colab-df-spinner {\n",
" border: 2px solid var(--fill-color);\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" animation:\n",
" spin 1s steps(1) infinite;\n",
" }\n",
"\n",
" @keyframes spin {\n",
" 0% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" border-left-color: var(--fill-color);\n",
" }\n",
" 20% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 30% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 40% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 60% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 80% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" 90% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" }\n",
"</style>\n",
"\n",
" <script>\n",
" async function quickchart(key) {\n",
" const quickchartButtonEl =\n",
" document.querySelector('#' + key + ' button');\n",
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
" try {\n",
" const charts = await google.colab.kernel.invokeFunction(\n",
" 'suggestCharts', [key], {});\n",
" } catch (error) {\n",
" console.error('Error during call to suggestCharts:', error);\n",
" }\n",
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
" }\n",
" (() => {\n",
" let quickchartButtonEl =\n",
" document.querySelector('#df-6bbc5ab8-700b-480a-8b42-cde2ec18e639 button');\n",
" quickchartButtonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
" })();\n",
" </script>\n",
"</div>\n",
"\n",
" </div>\n",
" </div>\n"
]
},
"metadata": {},
"execution_count": 4
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "8_hGe9FE13a1"
},
"source": [
"df = df[df.index==\"current\"].dropna(axis=1).T"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tWyF7-7r2wsE",
"outputId": "09f25917-86c6-4003-b9bd-bd59eb8c5952"
},
"source": [
"df[\"current\"][0]"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'esg_rating': 'aaa', 'esg_category': 'leader'}"
]
},
"metadata": {},
"execution_count": 15
}
]
},
{
"cell_type": "code",
"source": [
"df.iloc[0][0][\"esg_rating\"]"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"id": "wDU1MzE7oNp8",
"outputId": "33c93db3-0a40-4dc3-e534-d8ef24309935"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'aaa'"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
}
},
"metadata": {},
"execution_count": 16
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "YmfwLXju2cv9"
},
"source": [
"df[\"risk\"] = df[\"current\"].apply(lambda x: x[\"esg_rating\"])"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "k5an1b463JRh"
},
"source": [
"rep = {\"ccc\":7, \"b\":6, \"bb\":5, \"bbb\":4, \"a\":3, \"aa\":2, \"aaa\":1}"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "jaeJJP4e5AqU"
},
"source": [
"df.index.name = \"Ticker\""
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "DS_aMX-U4a5G"
},
"source": [
"df=df.replace({\"risk\": rep})"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "hUZB717R5IwD"
},
"source": [
"df[\"risk\"] = df[\"risk\"]/df[\"risk\"].max()"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "maB7hl3b1Vf9"
},
"source": [
"df = df.reset_index()"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "NgAkzV347Tl1",
"outputId": "7b32b954-52ea-4f7e-ad62-bdf360e6440a"
},
"source": [
"df.head()"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Ticker current risk\n",
"0 MMM {'esg_rating': 'aaa', 'esg_category': 'leader'} 0.142857\n",
"1 AOS {'esg_rating': 'bbb', 'esg_category': 'average'} 0.571429\n",
"2 ABBV {'esg_rating': 'a', 'esg_category': 'average'} 0.428571\n",
"3 ACN {'esg_rating': 'a', 'esg_category': 'average'} 0.428571\n",
"4 AES {'esg_rating': 'a', 'esg_category': 'average'} 0.428571"
],
"text/html": [
"\n",
" <div id=\"df-a86ce554-92df-4fb6-a2a1-5c811d31e578\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Ticker</th>\n",
" <th>current</th>\n",
" <th>risk</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>MMM</td>\n",
" <td>{'esg_rating': 'aaa', 'esg_category': 'leader'}</td>\n",
" <td>0.142857</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>AOS</td>\n",
" <td>{'esg_rating': 'bbb', 'esg_category': 'average'}</td>\n",
" <td>0.571429</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>ABBV</td>\n",
" <td>{'esg_rating': 'a', 'esg_category': 'average'}</td>\n",
" <td>0.428571</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>ACN</td>\n",
" <td>{'esg_rating': 'a', 'esg_category': 'average'}</td>\n",
" <td>0.428571</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>AES</td>\n",
" <td>{'esg_rating': 'a', 'esg_category': 'average'}</td>\n",
" <td>0.428571</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a86ce554-92df-4fb6-a2a1-5c811d31e578')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-a86ce554-92df-4fb6-a2a1-5c811d31e578 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-a86ce554-92df-4fb6-a2a1-5c811d31e578');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 23
}
]
},
{
"cell_type": "code",
"source": [
"df.sort_values(\"risk\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 423
},
"id": "lKj954eYdZEd",
"outputId": "72e0e56c-a66c-4ff4-fd18-b3f2f08b4d07"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Ticker current risk\n",
"0 MMM {'esg_rating': 'aaa', 'esg_category': 'leader'} 0.142857\n",
"89 ECL {'esg_rating': 'aaa', 'esg_category': 'leader'} 0.142857\n",
"101 EXPD {'esg_rating': 'aaa', 'esg_category': 'leader'} 0.142857\n",
"123 GWW {'esg_rating': 'aaa', 'esg_category': 'leader'} 0.142857\n",
"154 JCI {'esg_rating': 'aaa', 'esg_category': 'leader'} 0.142857\n",
".. ... ... ...\n",
"203 NWSA {'esg_rating': 'ccc', 'esg_category': 'laggard'} 1.000000\n",
"204 NWS {'esg_rating': 'ccc', 'esg_category': 'laggard'} 1.000000\n",
"83 DISH {'esg_rating': 'ccc', 'esg_category': 'laggard'} 1.000000\n",
"152 SJM {'esg_rating': 'ccc', 'esg_category': 'laggard'} 1.000000\n",
"192 MNST {'esg_rating': 'ccc', 'esg_category': 'laggard'} 1.000000\n",
"\n",
"[296 rows x 3 columns]"
],
"text/html": [
"\n",
" <div id=\"df-a2bfa111-93e2-4fe0-8fcc-fd622ddd6ef3\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Ticker</th>\n",
" <th>current</th>\n",
" <th>risk</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>MMM</td>\n",
" <td>{'esg_rating': 'aaa', 'esg_category': 'leader'}</td>\n",
" <td>0.142857</td>\n",
" </tr>\n",
" <tr>\n",
" <th>89</th>\n",
" <td>ECL</td>\n",
" <td>{'esg_rating': 'aaa', 'esg_category': 'leader'}</td>\n",
" <td>0.142857</td>\n",
" </tr>\n",
" <tr>\n",
" <th>101</th>\n",
" <td>EXPD</td>\n",
" <td>{'esg_rating': 'aaa', 'esg_category': 'leader'}</td>\n",
" <td>0.142857</td>\n",
" </tr>\n",
" <tr>\n",
" <th>123</th>\n",
" <td>GWW</td>\n",
" <td>{'esg_rating': 'aaa', 'esg_category': 'leader'}</td>\n",
" <td>0.142857</td>\n",
" </tr>\n",
" <tr>\n",
" <th>154</th>\n",
" <td>JCI</td>\n",
" <td>{'esg_rating': 'aaa', 'esg_category': 'leader'}</td>\n",
" <td>0.142857</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>203</th>\n",
" <td>NWSA</td>\n",
" <td>{'esg_rating': 'ccc', 'esg_category': 'laggard'}</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>204</th>\n",
" <td>NWS</td>\n",
" <td>{'esg_rating': 'ccc', 'esg_category': 'laggard'}</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>83</th>\n",
" <td>DISH</td>\n",
" <td>{'esg_rating': 'ccc', 'esg_category': 'laggard'}</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>152</th>\n",
" <td>SJM</td>\n",
" <td>{'esg_rating': 'ccc', 'esg_category': 'laggard'}</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>192</th>\n",
" <td>MNST</td>\n",
" <td>{'esg_rating': 'ccc', 'esg_category': 'laggard'}</td>\n",
" <td>1.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>296 rows × 3 columns</p>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a2bfa111-93e2-4fe0-8fcc-fd622ddd6ef3')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-a2bfa111-93e2-4fe0-8fcc-fd622ddd6ef3 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-a2bfa111-93e2-4fe0-8fcc-fd622ddd6ef3');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 24
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "4KTRZcVgFDUo"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment