{"cells":[{"metadata":{},"cell_type":"markdown","source":"# **FAILURE TO PLAN IS A PLAN TO FAIL**"},{"metadata":{},"cell_type":"markdown","source":"This is just a preliminary workbook for the 11/4 visualization and external datasets. Below you'll find the first visualizations out of the analysis I'm undertaking as part of this project. As shown above, I'm looking at the contrast between how well countries/cities are planning/preparing on climate change, how they're dealing with chronic issues (such as long term mortality rates, which will serve as a proxy to how well they will deal with longterm damage being realized by climate change) and how they're dealing with the onset of the pandemic (which is my proxy to sudden life altering events that will become more frequent as climate change continues to accelerate). It is my belief that having proper procedures and planning in place is absolutely essential, however as my analysis below shows and will continue to show even this basic step is already setting many people at a possibly catastrophic disadvantage. Thus, I'm anticipating that my overall analysis will show that an outreach program to the most vulnerable areas will be most effective. I will then leverage the companies dataset to comeup with possibly climate change responsible partners to go along with in this endeavor. \n"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Hidden: imported libraries and setting up paths"},{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np  # linear algebra\nimport pandas as pd  # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport  seaborn as sns\nimport matplotlib.pyplot as plt\n \n\nPATH = '../input/cdp-unlocking-climate-solutions/Cities/'\nPATH2 = '../input/cdp-unlocking-climate-solutions/Corporations/'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data2020 = pd.read_csv(PATH + 'Cities Responses/2020_Full_Cities_Dataset.csv')\ndata2019 = pd.read_csv(PATH + 'Cities Responses/2019_Full_Cities_Dataset.csv')\ndata2018 = pd.read_csv(PATH + 'Cities Responses/2018_Full_Cities_Dataset.csv')\ndata2020b = pd.read_csv(PATH + 'Cities Disclosing/2020_Cities_Disclosing_to_CDP.csv')\ndata2019b = pd.read_csv(PATH + 'Cities Disclosing/2019_Cities_Disclosing_to_CDP.csv')\ndata2018b = pd.read_csv(PATH + 'Cities Disclosing/2018_Cities_Disclosing_to_CDP.csv')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"from ipywidgets import interact, interactive, fixed, interact_manual\nimport ipywidgets as widgets","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import plotly_express as px\nfrom plotly.offline import init_notebook_mode\ninit_notebook_mode(connected=True)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"![](http://)Build Data Frames"},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcat = pd.concat([data2020, data2019, data2018])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatb = pd.concat([data2020b, data2019b, data2018b])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatmerge=dataconcat\ndataconcatmerge['match'] = dataconcatmerge['Year Reported to CDP'].astype(str) + dataconcatmerge['Account Number'].astype(str)\ndataconcatmerge.head(2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatmergeb=dataconcatb\ndataconcatmergeb['match'] = dataconcatmergeb['Year Reported to CDP'].astype(str) + dataconcatmergeb['Account Number'].astype(str)\ndataconcatmergeb = dataconcatmergeb[['match', 'Population', 'Access']]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatmerged = dataconcatmerge.merge(dataconcatmergeb, on='match')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatmergedtoQ2 = dataconcatmerged[['match','Population']]\ndataconcatmergedtoQ2 = dataconcatmergedtoQ2.drop_duplicates()\ndataconcatmergedtoQ2.head(3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcat.groupby('Year Reported to CDP')['Account Number'].nunique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatQ220 = dataconcat[dataconcat['Question Name']=='Has a climate change risk and vulnerability assessment been undertaken for your city?']\ndataconcatQ219 = dataconcat[dataconcat['Question Name']=='Has a climate change risk and vulnerability assessment been undertaken for the city area?']\ndataconcatQ218 = dataconcat[dataconcat['Question Name']=='Has a climate change risk or vulnerability assessment been undertaken for your local government area?']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatQ2 = pd.concat([dataconcatQ220, dataconcatQ219, dataconcatQ218])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatQ2['Response Answer'] =  dataconcatQ2['Response Answer'].replace(['Intending to undertake in the next 2 years'], 'Intending to undertake in future')\ndataconcatQ2['Response Answer'] =  dataconcatQ2['Response Answer'].replace(['No'],'Not intending to undertake')\ndataconcatQ2['count'] = 1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def f(x):\n    return x","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatQ2['match'] = dataconcatQ2['Year Reported to CDP'].astype(str) + dataconcatQ2['Account Number'].astype(str)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatQ2merged = dataconcatQ2.merge(dataconcatmergedtoQ2, how='inner', on='match')\ndataconcatQ2 = dataconcatQ2merged\ndataconcatQ2.head(2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatQ2['Population'].values[dataconcatQ2['Population']>25000000] =0","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataconcatQ2 = dataconcatQ2[['Year Reported to CDP', 'Country', 'CDP Region', 'Population', 'count', 'Response Answer']]\ndataconcatQ2.head(4)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Good news, it appears that higher percentage of respondents have a climate change plan in year-over-year comparisons."},{"metadata":{"trusted":true},"cell_type":"code","source":"def f(year):\n    df2 = dataconcatQ2\n    fig = px.pie(df2[df2['Year Reported to CDP'] ==year], values = 'count', names ='Response Answer')\n    fig.show()\ninteract(f, year=[2020,2019,2018])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Also, More people are living in areas with a climate change plan, overall this is great news. In 2020, apx 1 in 5 people represented by this population survey live in a city without a climate change plan in hand (apx. 109.25 Million people). This is a better ratio than in 2018 where 3 in 10 people represented by this population survey lived in a city without a climate change plan in hand; however that is still a very high number. As climate change accelerates these individuals are becoming more and more vulnerable to sudden/rapid changes in climate driven events. "},{"metadata":{"trusted":true},"cell_type":"code","source":"def f(year):\n    df2 = dataconcatQ2\n    fig = px.pie(df2[df2['Year Reported to CDP'] ==year], values = 'Population', names ='Response Answer')\n    fig.show()\ninteract(f, year=[2020,2019,2018])","execution_count":null,"outputs":[]}],"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}