{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Analysis on response data about climate change and suggesion for cities and corporations\n"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"path_cities = \"/kaggle/input/cdp-unlocking-climate-solutions/Cities/\"\npath_corp = \"/kaggle/input/cdp-unlocking-climate-solutions/Corporations/\"\npath_suppl = \"/kaggle/input/cdp-unlocking-climate-solutions/Supplementary Data/\"\npath_out = \"/kaggle/output/\"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# EDA on corporations data(2020)\nThe latest data of climate change were used."},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"disclose_cc = pd.read_csv(path_corp + \"Corporations Disclosing/Climate Change/2020_Corporates_Disclosing_to_CDP_Climate_Change.csv\")\nprint(\"columns of disclose_cc: \", disclose_cc.columns)\nresponse_cc = pd.read_csv(path_corp + \"Corporations Responses/Climate Change/2020_Full_Climate_Change_Dataset.csv\")\nprint(\"columns of response_cc: \", response_cc.columns)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"shape of disclose_cc: \", disclose_cc.shape)\nprint(\"number of organizations: \", disclose_cc[\"organization\"].nunique())\ndisclose_cc.head(3)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## analyze corporations and their types.\nPrimary_sector and industries are the best for grouping corporations.\\\nI chose primary_sector as the best category at the end because primary_sector is relatively even and can describe each corpotaion's features."},{"metadata":{"trusted":true},"cell_type":"code","source":"def count_unique_value(df, columns):\n    count_dict = {}\n    for col in columns:\n        count_dict[col] = df[col].nunique()\n    print(count_dict)\n        \ncount_unique_value(disclose_cc, [\"account_number\", \"activities\", \"primary_activity\", \"sectors\", \"primary_sector\", \"industries\"])\nprint(disclose_cc[\"primary_sector\"].value_counts())\nprint(\"##############################\")\nprint(disclose_cc[\"industries\"].value_counts())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# get primary_sector dict for mapping\norganization = list(disclose_cc[\"organization\"])\nprimary_sector = list(disclose_cc[\"primary_sector\"])\norganization_map = dict(zip(organization, primary_sector))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## analyze response data from corporations (climate change)"},{"metadata":{"trusted":true},"cell_type":"code","source":"print(\"shape of response_cc: \", response_cc.shape)\nprint(\"columns:\",list(response_cc.columns))\nprint(\"number of organizations: \", response_cc[\"organization\"].nunique())\n# add column \"primary_sector\"\nresponse_cc[\"primary_sector\"] = response_cc[\"organization\"].map(organization_map)\nresponse_cc.head(3)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"analyze emission data\\\nScope1 emission data are listed in the question C6.1\\\nscope 1 emission:\nEmissions from operations that are owned or controlled by the\nreporting company"},{"metadata":{"trusted":true},"cell_type":"code","source":"response_c6_1 = response_cc[response_cc[\"question_number\"] == \"C6.1\"]\n# take Iron Mountain Inc. as an example\nresponse_c6_1_IronMountain = response_c6_1[response_c6_1[\"organization\"] == \"Iron Mountain Inc.\"]\ndef sort_df_along_row_and_column_number(df):\n    return df.sort_values(\"row_number\").sort_values(\"column_number\")\ndef get_scope1_emission(df):\n    return df[df[\"table_columns_unique_reference\"] == \"C6.1_c1-Gross global Scope 1 emissions (metric tons CO2e)\"]\nprint(\"Iron Mountain Inc.'s response to the question C6.1'\")\nsort_df_along_row_and_column_number(response_c6_1_IronMountain)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# focus on emission figures\nsort_df_along_row_and_column_number(get_scope1_emission(response_c6_1_IronMountain))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## emission difference among sectors\n### scope1 emission in 2019\nSome sectors emit much more gas than others."},{"metadata":{"trusted":true},"cell_type":"code","source":"response_c6_1_4years = get_scope1_emission(response_c6_1)\n# each organizeation's scope1 emission in 2019 (2019/01/01 - 2019/12/31)\nresponse_c6_1_2019 = response_c6_1_4years[response_c6_1_4years[\"row_name\"] == \"Reporting year\"]\nresponse_c6_1_2019 = response_c6_1_2019.astype({'response_value': float})\n\nfig = plt.figure(figsize=(30,10))\nax = fig.add_subplot(1, 1, 1)\nsns.boxplot(x = \"primary_sector\",y = \"response_value\",data= response_c6_1_2019, showfliers=False, ax=ax)\nsns.stripplot(x = \"primary_sector\",y = \"response_value\",data= response_c6_1_2019, jitter=True, color='black', ax=ax)\nplt.xticks(rotation=90)\nplt.title(\"scope1 emission\")\nplt.show()\n# response_c6_1_2019[[\"primary_sector\",\"response_value\"]].groupby(\"primary_sector\").describe()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"another look at the sector difference with a pie chart"},{"metadata":{"trusted":true},"cell_type":"code","source":"response_c6_1_2019_sectorsum = response_c6_1_2019.groupby(\"primary_sector\").sum()[[\"response_value\"]]\nresponse_c6_1_2019_sectorsum = response_c6_1_2019_sectorsum.sort_values(\"response_value\", ascending=False)\n\n# convert 45 small-emission sectors to \"others\"\nn_others = 45\nscope1_others = pd.Series([response_c6_1_2019_sectorsum.tail(n_others).sum()[\"response_value\"]],\n                   index=response_c6_1_2019_sectorsum.columns, name='others')\nresponse_c6_1_2019_sectorsum = response_c6_1_2019_sectorsum.iloc[:-n_others,:].append(scope1_others)\nprint(\"Now the number of sectors is\", len(response_c6_1_2019_sectorsum))\ntotal_scope1_emission = round(response_c6_1_2019_sectorsum[\"response_value\"].sum())\nprint(\"Total scope1 emission: \", total_scope1_emission, \"t\")\n\n# plot pie chart\ndef plot_piechart(pandas_series, title):\n    fig = plt.figure()\n    ax = fig.add_subplot(1, 1, 1)\n    ax.pie(pandas_series.values,\n           labels=list(pandas_series.index),\n           autopct=\"%1.1f%%\",\n          startangle=90,\n          counterclock=False)\n    plt.title(title)\n    plt.show()\nplot_piechart(response_c6_1_2019_sectorsum[\"response_value\"], \"scope1 emission\")\ndel scope1_others\ndel response_c6_1_2019_sectorsum\ndel response_c6_1_2019","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Now, you can see which sectors matter.\\\nSectors with 5% of share or more : \n* Thermal power generation,\n* Energy utility networks,\n* Air transport,\n* Chemicals,\n* Oil & gas extraction & production"},{"metadata":{},"cell_type":"markdown","source":"### scope2 emission in 2019\nScope2 emission data are listed in the question 6.3.\\\nscope2 emission:\\\nIndirect emissions from the generation of purchased or acquired\nelectricity, steam, heat or cooling consumed by the reporting\ncompany"},{"metadata":{"trusted":true},"cell_type":"code","source":"response_c6_3 = response_cc[response_cc[\"question_number\"] == \"C6.3\"]\ndef get_scope2_emission(df):\n    return df[df[\"table_columns_unique_reference\"] == \"C6.3_c1-Scope 2, location-based\"]\nresponse_c6_3_4years = get_scope2_emission(response_c6_3)\n# each organizeation's scope2 emission in 2019 (2019/01/01 - 2019/12/31)\nresponse_c6_3_2019 = response_c6_3_4years[response_c6_3_4years[\"row_name\"] == \"Reporting year\"]\nresponse_c6_3_2019 = response_c6_3_2019.astype({'response_value': float})\n\nfig = plt.figure(figsize=(30,10))\nax = fig.add_subplot(1, 1, 1)\nsns.boxplot(x = \"primary_sector\",y = \"response_value\",data= response_c6_3_2019, showfliers=False, ax=ax)\nsns.stripplot(x = \"primary_sector\",y = \"response_value\",data= response_c6_3_2019, jitter=True, color='black', ax=ax)\nplt.xticks(rotation=90)\nplt.title(\"scope2 emission\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"another look at the sector difference with a pie chart\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"response_c6_3_2019_sectorsum = response_c6_3_2019.groupby(\"primary_sector\").sum()[[\"response_value\"]]\nresponse_c6_3_2019_sectorsum = response_c6_3_2019_sectorsum.sort_values(\"response_value\", ascending=False)\n\n# convert 45 small-emission sectors to \"others\"\nn_others = 45\nscope2_others = pd.Series([response_c6_3_2019_sectorsum.tail(n_others).sum()[\"response_value\"]],\n                   index=response_c6_3_2019_sectorsum.columns, name='others')\n\nresponse_c6_3_2019_sectorsum = response_c6_3_2019_sectorsum.iloc[:-n_others,:].append(scope2_others)\nprint(\"Now the number of sectors is\", len(response_c6_3_2019_sectorsum))\ntotal_scope2_emission = round(response_c6_3_2019_sectorsum[\"response_value\"].sum())\nprint(\"Total scope2 emission: \", total_scope2_emission, \"t\")\nprint(\"The figure is \", round(total_scope2_emission*100/total_scope1_emission,1), \"% of total scope1 emission\")\n\nplot_piechart(response_c6_3_2019_sectorsum[\"response_value\"], \"scope2 emission\")\ndel scope2_others\ndel response_c6_3_2019_sectorsum\ndel response_c6_3_2019\ndel response_cc","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Except the chemicas sector, the scope2 indirect emission is relatively even-distributed, which means that scope1 direct emission from some top sectors is evenly shared by other sectors.\\\n\nHere I propose two approaches for reducing GHG emission.\n1. approach to energy generators\n1. approach to energy consumers.\\\n(In this notebook I am going to focus on corporaion consumers)"},{"metadata":{},"cell_type":"markdown","source":"# EDA on cities data(2020)\nanalyze cities data to consider the two approaches above."},{"metadata":{"trusted":true},"cell_type":"code","source":"city_response = pd.read_csv(path_cities + \"Cities Responses/2020_Full_Cities_Dataset.csv\")\nprint(\"shape of city_2020:\", city_response.shape)\nprint(\"columns:\",list(city_response.columns))\nprint(\"number of organizations: \", city_response[\"Organization\"].nunique())\nprint(\"number of countries: \", city_response[\"Country\"].nunique())\n# use the same column names as that used in the dataframe response_cc\ncity_response.rename(columns={'Row Number': 'row_number', 'Column Number': 'column_number'}, inplace=True)\ncity_response.head(3)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"1. approach to energy generators\\\nanalyze question 8 (Energy section)"},{"metadata":{"trusted":true},"cell_type":"code","source":"# each organization's answer to question 8.0\nquestion_number = \"8.0\"\nprint(f\"question {question_number}:\", city_response[city_response[\"Question Number\"]== question_number].head(1)[\"Question Name\"].values)\ncity_8_0 = city_response[city_response[\"Question Number\"]== question_number][\"Response Answer\"].value_counts(dropna=False)\nplot_piechart(city_8_0, \"resoponse to question 8.0\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"You can see that many cities think renewable energy as an important matter."},{"metadata":{"trusted":true},"cell_type":"code","source":"question_number = \"8.0a\"\ncity_8_0_a = city_response[city_response[\"Question Number\"]== question_number]\nprint(f\"question {question_number}:\", city_8_0_a.head(1)[\"Question Name\"].values)\ncity_8_0_a_base = city_8_0_a[city_8_0_a[\"Column Name\"] == \"Base year\"][\"Response Answer\"].value_counts(dropna=False)\ncity_8_0_a_target = city_8_0_a[city_8_0_a[\"Column Name\"] == \"Target year\"][\"Response Answer\"].value_counts(dropna=False)\nprint(\"Total answers concerning base/target year:\", city_8_0_a_base.sum())\nprint(\"Responses from\", city_8_0[city_8_0.index==\"Yes\"].values, \"organizations\")\n# convert 25 small-emission sectors to \"others\"\nn_others = 15\nothers_8_0_a_base = pd.Series([city_8_0_a_base.tail(n_others).sum()],\n                   index=['others'], name=city_8_0_a_base.name)\ncity_8_0_a_base = city_8_0_a_base[:-n_others].append(others_8_0_a_base)\nothers_8_0_a_target = pd.Series([city_8_0_a_target.tail(n_others).sum()],\n                   index=['others'], name=city_8_0_a_target.name)\ncity_8_0_a_target = city_8_0_a_target[:-n_others].append(others_8_0_a_target)\ntitles = [\"base year\", \"target year\"]\nseries = [city_8_0_a_base, city_8_0_a_target]\nplt.figure(figsize=(15,6))\nfor i in range(2):\n    plt.subplot(1,2,i+1)\n    plt.title(titles[i])\n    plt.pie(series[i].values,\n       labels=list(series[i].index),\n       autopct=\"%1.1f%%\",\n      startangle=90,\n      counterclock=False)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"These graphs suggest that base year is more various among organizations than target year, which means it is difficult to compare targets each organizaions set.\\\nHalf of the responses were \"Question not applicable\"."},{"metadata":{},"cell_type":"markdown","source":"I think the difficulty of comparing targets with others leads to slow speed of cities' actions toward climate change. We may need to make great effort on climate change as corporations do to win their market. Some competition system would change our attitude to climate change."},{"metadata":{},"cell_type":"markdown","source":"2. approach to energy cosumers\\\nanalyze question 8.5 (Energy section)(includes approach 1)"},{"metadata":{"trusted":true},"cell_type":"code","source":"# each organization's answer to question 8.5\nquestion_number = \"8.5\"\nprint(f\"question {question_number}:\", city_response[city_response[\"Question Number\"]== question_number].head(1)[\"Question Name\"].values)\ncity_8_5 = city_response[city_response[\"Question Number\"]== question_number][\"Response Answer\"].value_counts(dropna=False)\nplot_piechart(city_8_5, \"response to question 8.5\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Only 44% of respondants said \"Yes\" or \"In progress\""},{"metadata":{},"cell_type":"markdown","source":"Cities have to take action to improve energy efficiency more quickly. The figure tells you that discussions on efficiency has been looked over."},{"metadata":{},"cell_type":"markdown","source":"analyze target sectors concerning energy efficiency in detail"},{"metadata":{"trusted":true},"cell_type":"code","source":"question_number = \"8.5a\"\nprint(f\"question {question_number}:\", city_response[city_response[\"Question Number\"]== question_number].head(1)[\"Question Name\"].values)\ncity_8_5_a = city_response[city_response[\"Question Number\"]== question_number]\ncity_8_5_a = city_8_5_a[city_8_5_a[\"Column Name\"]==\"Please indicate to which energy sector(s) the target applies (Multiple choice)\"]\ncity_8_5_a = city_8_5_a[\"Response Answer\"].value_counts(dropna=False)\n\n# convert 25 small-emission sectors to \"others\"\nn_others = 25\nothers_8_5_a = pd.Series([city_8_5_a.tail(n_others).sum()],\n                   index=['others'], name=city_8_5_a.name)\ncity_8_5_a = city_8_5_a[:-n_others].append(others_8_5_a)\nprint(\"Total answers:\", city_8_5_a.sum())\nprint(\"from\", city_8_5[city_8_5.index==\"Yes\"].values, \"organizations\")\nplot_piechart(city_8_5_a, \"response to question 8.5a\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* \"Question not applicable\" made up about 40% \n* lack of variety"},{"metadata":{},"cell_type":"markdown","source":"I would recommend cities get more sectors engaged in their efficiency target. Since all sectors are indirext emitters of green house gas as shown in the graph of scope2 emission, they should contribute to some target. Cities can accelerate corporation actions by setting a tax or help new investment on utilities contributing to efficiency by loosing ristrictions."},{"metadata":{},"cell_type":"markdown","source":"## Conclusion\nIn conclusion I would suggest following KPI for cities and corporaions;\n* Easiness to compare disclosed figures of an organization with other organizations (whether it uses the same baseline, same protocol)\n* Variety of sectors, stakeholders and people an organization get involved in its mitigation action toward climate change.\n* eagerness to improve energy efficiency of an arganization regardless of its sector"},{"metadata":{},"cell_type":"markdown","source":"There is no discussion on verification of emissions in this notebook since verification data were removed from the corporations response dataset. However, we have to see whether verification proceses work or not in order to precisely understand the current emission of green house gas and its impact, which will lead to better actions to climate change."}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}