{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# About Dataset\n", "\n", "Context\n", "\n", "Methane is responsible for around 30% of the rise in global temperatures since the Industrial Revolution, and rapid and sustained reductions in methane emissions are key to limiting near-term global warming and improving air quality. The energy sector – including oil, natural gas, coal and bioenergy – accounts for nearly 40% of methane emissions from human activity.\n", "\n", "Content\n", "The following dataset has information about methane gas emissions globally. Details about the columns are as follows:\n", "\n", "region -\n", "country - Country of Emission.\n", "emissions - Methane Emissions in kt.\n", "type - Sector from which emissions occur.\n", "Segment- Sub-sector from which emissions occur.\n", "reason - The reason for the emission.\n", "ba\n", "seYear - Base year for the tracking of emissions.\n", "notes - The source of data\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:09.717145Z", "iopub.status.busy": "2023-04-12T16:58:09.716781Z", "iopub.status.idle": "2023-04-12T16:58:13.478891Z", "shell.execute_reply": "2023-04-12T16:58:13.477037Z", "shell.execute_reply.started": "2023-04-12T16:58:09.717110Z" } }, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "import plotly.express as px\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.483139Z", "iopub.status.busy": "2023-04-12T16:58:13.482412Z", "iopub.status.idle": "2023-04-12T16:58:13.527322Z", "shell.execute_reply": "2023-04-12T16:58:13.526378Z", "shell.execute_reply.started": "2023-04-12T16:58:13.483059Z" } }, "outputs": [], "source": [ "df=pd.read_csv(\"data/Methane_final.csv\")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.529325Z", "iopub.status.busy": "2023-04-12T16:58:13.528892Z", "iopub.status.idle": "2023-04-12T16:58:13.560083Z", "shell.execute_reply": "2023-04-12T16:58:13.559005Z", "shell.execute_reply.started": "2023-04-12T16:58:13.529284Z" } }, "outputs": [], "source": [ "df.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.563328Z", "iopub.status.busy": "2023-04-12T16:58:13.562761Z", "iopub.status.idle": "2023-04-12T16:58:13.571481Z", "shell.execute_reply": "2023-04-12T16:58:13.568955Z", "shell.execute_reply.started": "2023-04-12T16:58:13.563289Z" } }, "outputs": [], "source": [ "df.columns\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.573802Z", "iopub.status.busy": "2023-04-12T16:58:13.573427Z", "iopub.status.idle": "2023-04-12T16:58:13.588847Z", "shell.execute_reply": "2023-04-12T16:58:13.587379Z", "shell.execute_reply.started": "2023-04-12T16:58:13.573767Z" } }, "outputs": [], "source": [ "df.shape" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.591898Z", "iopub.status.busy": "2023-04-12T16:58:13.591420Z", "iopub.status.idle": "2023-04-12T16:58:13.627322Z", "shell.execute_reply": "2023-04-12T16:58:13.626409Z", "shell.execute_reply.started": "2023-04-12T16:58:13.591857Z" } }, "outputs": [], "source": [ "df.info()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.629190Z", "iopub.status.busy": "2023-04-12T16:58:13.628698Z", "iopub.status.idle": "2023-04-12T16:58:13.650829Z", "shell.execute_reply": "2023-04-12T16:58:13.649646Z", "shell.execute_reply.started": "2023-04-12T16:58:13.629152Z" }, "scrolled": true }, "outputs": [], "source": [ "df" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.652901Z", "iopub.status.busy": "2023-04-12T16:58:13.652305Z", "iopub.status.idle": "2023-04-12T16:58:13.660320Z", "shell.execute_reply": "2023-04-12T16:58:13.658308Z", "shell.execute_reply.started": "2023-04-12T16:58:13.652867Z" } }, "outputs": [], "source": [ "df.type.unique()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.662741Z", "iopub.status.busy": "2023-04-12T16:58:13.661829Z", "iopub.status.idle": "2023-04-12T16:58:13.674253Z", "shell.execute_reply": "2023-04-12T16:58:13.672844Z", "shell.execute_reply.started": "2023-04-12T16:58:13.662688Z" } }, "outputs": [], "source": [ "df.reason.unique()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.680101Z", "iopub.status.busy": "2023-04-12T16:58:13.679076Z", "iopub.status.idle": "2023-04-12T16:58:13.688523Z", "shell.execute_reply": "2023-04-12T16:58:13.687012Z", "shell.execute_reply.started": "2023-04-12T16:58:13.680056Z" } }, "outputs": [], "source": [ "df.region.unique()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.690937Z", "iopub.status.busy": "2023-04-12T16:58:13.690187Z", "iopub.status.idle": "2023-04-12T16:58:13.703265Z", "shell.execute_reply": "2023-04-12T16:58:13.702147Z", "shell.execute_reply.started": "2023-04-12T16:58:13.690892Z" } }, "outputs": [], "source": [ "df.reason=df.reason.astype('category')\n", "df.type=df.type.astype('category')\n", "df.region=df.region.astype('category')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.705427Z", "iopub.status.busy": "2023-04-12T16:58:13.704813Z", "iopub.status.idle": "2023-04-12T16:58:13.731409Z", "shell.execute_reply": "2023-04-12T16:58:13.729908Z", "shell.execute_reply.started": "2023-04-12T16:58:13.705385Z" } }, "outputs": [], "source": [ "df.info()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.733193Z", "iopub.status.busy": "2023-04-12T16:58:13.732800Z", "iopub.status.idle": "2023-04-12T16:58:13.741125Z", "shell.execute_reply": "2023-04-12T16:58:13.739619Z", "shell.execute_reply.started": "2023-04-12T16:58:13.733152Z" } }, "outputs": [], "source": [ "df.drop(columns=['Unnamed: 0'],inplace=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.743153Z", "iopub.status.busy": "2023-04-12T16:58:13.742728Z", "iopub.status.idle": "2023-04-12T16:58:13.762842Z", "shell.execute_reply": "2023-04-12T16:58:13.761949Z", "shell.execute_reply.started": "2023-04-12T16:58:13.743111Z" } }, "outputs": [], "source": [ "df.head(2)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.765226Z", "iopub.status.busy": "2023-04-12T16:58:13.764548Z", "iopub.status.idle": "2023-04-12T16:58:13.772765Z", "shell.execute_reply": "2023-04-12T16:58:13.771954Z", "shell.execute_reply.started": "2023-04-12T16:58:13.765187Z" } }, "outputs": [], "source": [ "df.emissions=df.emissions.apply(lambda x:round(x,2))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.774881Z", "iopub.status.busy": "2023-04-12T16:58:13.774188Z", "iopub.status.idle": "2023-04-12T16:58:13.787058Z", "shell.execute_reply": "2023-04-12T16:58:13.786106Z", "shell.execute_reply.started": "2023-04-12T16:58:13.774840Z" } }, "outputs": [], "source": [ "df.isnull().sum()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.789464Z", "iopub.status.busy": "2023-04-12T16:58:13.788757Z", "iopub.status.idle": "2023-04-12T16:58:13.806040Z", "shell.execute_reply": "2023-04-12T16:58:13.804671Z", "shell.execute_reply.started": "2023-04-12T16:58:13.789403Z" } }, "outputs": [], "source": [ "df.duplicated().sum()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.808188Z", "iopub.status.busy": "2023-04-12T16:58:13.807474Z", "iopub.status.idle": "2023-04-12T16:58:13.827909Z", "shell.execute_reply": "2023-04-12T16:58:13.826783Z", "shell.execute_reply.started": "2023-04-12T16:58:13.808144Z" } }, "outputs": [], "source": [ "df.describe().T" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.830033Z", "iopub.status.busy": "2023-04-12T16:58:13.829427Z", "iopub.status.idle": "2023-04-12T16:58:13.840782Z", "shell.execute_reply": "2023-04-12T16:58:13.839534Z", "shell.execute_reply.started": "2023-04-12T16:58:13.829998Z" } }, "outputs": [], "source": [ "df.baseYear.value_counts()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.842986Z", "iopub.status.busy": "2023-04-12T16:58:13.842250Z", "iopub.status.idle": "2023-04-12T16:58:13.862485Z", "shell.execute_reply": "2023-04-12T16:58:13.861467Z", "shell.execute_reply.started": "2023-04-12T16:58:13.842939Z" } }, "outputs": [], "source": [ "df.head()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.863938Z", "iopub.status.busy": "2023-04-12T16:58:13.863611Z", "iopub.status.idle": "2023-04-12T16:58:13.874576Z", "shell.execute_reply": "2023-04-12T16:58:13.872683Z", "shell.execute_reply.started": "2023-04-12T16:58:13.863912Z" } }, "outputs": [], "source": [ "df.baseYear=df.baseYear.replace(\"2019-2021\",2020)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.879267Z", "iopub.status.busy": "2023-04-12T16:58:13.876077Z", "iopub.status.idle": "2023-04-12T16:58:13.888744Z", "shell.execute_reply": "2023-04-12T16:58:13.887719Z", "shell.execute_reply.started": "2023-04-12T16:58:13.879223Z" } }, "outputs": [], "source": [ "df.baseYear.value_counts()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.890705Z", "iopub.status.busy": "2023-04-12T16:58:13.890306Z", "iopub.status.idle": "2023-04-12T16:58:13.898952Z", "shell.execute_reply": "2023-04-12T16:58:13.897787Z", "shell.execute_reply.started": "2023-04-12T16:58:13.890670Z" } }, "outputs": [], "source": [ "#df['baseYear']= pd.to_datetime(df['baseYear'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.901003Z", "iopub.status.busy": "2023-04-12T16:58:13.900335Z", "iopub.status.idle": "2023-04-12T16:58:13.915303Z", "shell.execute_reply": "2023-04-12T16:58:13.914319Z", "shell.execute_reply.started": "2023-04-12T16:58:13.900965Z" } }, "outputs": [], "source": [ "df1=df[(df[\"region\"]!='World') & (df['segment']!='Total')]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.917577Z", "iopub.status.busy": "2023-04-12T16:58:13.916931Z", "iopub.status.idle": "2023-04-12T16:58:13.931241Z", "shell.execute_reply": "2023-04-12T16:58:13.930377Z", "shell.execute_reply.started": "2023-04-12T16:58:13.917535Z" } }, "outputs": [], "source": [ "max_emission_countries=df1.groupby(['region','country'])['emissions'].sum().reset_index()\n", "max_emission_countries.sort_values(by='emissions',ascending=False,inplace=True,ignore_index=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.933371Z", "iopub.status.busy": "2023-04-12T16:58:13.932709Z", "iopub.status.idle": "2023-04-12T16:58:13.937916Z", "shell.execute_reply": "2023-04-12T16:58:13.936837Z", "shell.execute_reply.started": "2023-04-12T16:58:13.933332Z" } }, "outputs": [], "source": [ "df2=max_emission_countries.head(10)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:13.939822Z", "iopub.status.busy": "2023-04-12T16:58:13.939202Z", "iopub.status.idle": "2023-04-12T16:58:15.767431Z", "shell.execute_reply": "2023-04-12T16:58:15.766162Z", "shell.execute_reply.started": "2023-04-12T16:58:13.939785Z" } }, "outputs": [], "source": [ "fig = px.pie(df2, names='country', values='emissions', hole=0.6, title='Emission per country',\n", " color_discrete_sequence=px.colors.qualitative.T10)\n", "fig.update_layout(title_text='Emission per country', title_x=0.5,height = 900)\n", "fig.update_traces(textposition='inside',textinfo='label+percent')\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:15.772903Z", "iopub.status.busy": "2023-04-12T16:58:15.772577Z", "iopub.status.idle": "2023-04-12T16:58:15.825918Z", "shell.execute_reply": "2023-04-12T16:58:15.824355Z", "shell.execute_reply.started": "2023-04-12T16:58:15.772874Z" } }, "outputs": [], "source": [ "#which year have maximum emission\n", "\n", "emission_per_year=df.groupby('baseYear').emissions.sum()\n", "fig = px.pie(emission_per_year, names=emission_per_year.index, values=emission_per_year.values, title='Emission per country',\n", " color_discrete_sequence=px.colors.qualitative.T10)\n", "fig.update_layout(title_text='Emission per year', title_x=0.5,height = 500)\n", "fig.update_traces(textposition='inside',textinfo='label+percent')\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:15.827790Z", "iopub.status.busy": "2023-04-12T16:58:15.827387Z", "iopub.status.idle": "2023-04-12T16:58:15.880977Z", "shell.execute_reply": "2023-04-12T16:58:15.879554Z", "shell.execute_reply.started": "2023-04-12T16:58:15.827753Z" } }, "outputs": [], "source": [ "fig = px.pie(df1, names='region', values='emissions', hole=0.6, title='Emission per country',\n", " color_discrete_sequence=px.colors.qualitative.T10)\n", "fig.update_layout(title_text='Emission per country', title_x=0.5,height = 900)\n", "fig.update_traces(textposition='inside',textinfo='label+percent')\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:58:15.882728Z", "iopub.status.busy": "2023-04-12T16:58:15.882355Z", "iopub.status.idle": "2023-04-12T16:58:16.043505Z", "shell.execute_reply": "2023-04-12T16:58:16.041643Z", "shell.execute_reply.started": "2023-04-12T16:58:15.882696Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":1: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n", " df6=df.groupby('region').get_group('Asia Pacific').sort_values(by='%percent emission')\n" ] }, { "ename": "KeyError", "evalue": "'%percent emission'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf6\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgroupby\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'region'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_group\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Asia Pacific'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msort_values\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mby\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'%percent emission'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36msort_values\u001b[0;34m(self, by, axis, ascending, inplace, kind, na_position, ignore_index, key)\u001b[0m\n\u001b[1;32m 6942\u001b[0m \u001b[0;31m# len(by) == 1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6943\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 6944\u001b[0;31m \u001b[0mk\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_get_label_or_level_values\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mby\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\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 6945\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6946\u001b[0m \u001b[0;31m# need to rewrap column in Series to apply key function\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m_get_label_or_level_values\u001b[0;34m(self, key, axis)\u001b[0m\n\u001b[1;32m 1842\u001b[0m \u001b[0mvalues\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maxes\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_level_values\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_values\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1843\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1844\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\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 1845\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1846\u001b[0m \u001b[0;31m# Check for duplicates\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mKeyError\u001b[0m: '%percent emission'" ] } ], "source": [ "df6=df.groupby('region').get_group('Asia Pacific').sort_values(by='%percent emission')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.status.busy": "2023-04-12T16:58:16.044320Z", "iopub.status.idle": "2023-04-12T16:58:16.044712Z", "shell.execute_reply": "2023-04-12T16:58:16.044551Z", "shell.execute_reply.started": "2023-04-12T16:58:16.044529Z" } }, "outputs": [], "source": [ "fig = px.pie(df6, names='country', values='emissions', hole=0.6, title='Emission per country',\n", " color_discrete_sequence=px.colors.qualitative.T10)\n", "fig.update_layout(title_text='Emission per country', title_x=0.5,height = 900)\n", "fig.update_traces(textposition='inside',textinfo='label+percent')\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.status.busy": "2023-04-12T16:58:16.049381Z", "iopub.status.idle": "2023-04-12T16:58:16.050653Z", "shell.execute_reply": "2023-04-12T16:58:16.050176Z", "shell.execute_reply.started": "2023-04-12T16:58:16.050137Z" } }, "outputs": [], "source": [ "df3=df.groupby(\"segment\").emissions.sum().reset_index().sort_values(by='emissions', ascending=False,ignore_index=True)\n", "df3" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.status.busy": "2023-04-12T16:58:16.051940Z", "iopub.status.idle": "2023-04-12T16:58:16.052480Z", "shell.execute_reply": "2023-04-12T16:58:16.052224Z", "shell.execute_reply.started": "2023-04-12T16:58:16.052195Z" } }, "outputs": [], "source": [ "#segment occurance having emission\n", "\n", "sns.countplot(data=df,y='segment',order=df.segment.value_counts().index[0:10])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.status.busy": "2023-04-12T16:58:16.054775Z", "iopub.status.idle": "2023-04-12T16:58:16.055289Z", "shell.execute_reply": "2023-04-12T16:58:16.055059Z", "shell.execute_reply.started": "2023-04-12T16:58:16.055032Z" } }, "outputs": [], "source": [ "df[\"%percent emission\"]= ((df[\"emissions\"]/df[\"emissions\"].sum())*100)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.status.busy": "2023-04-12T16:58:16.057017Z", "iopub.status.idle": "2023-04-12T16:58:16.057553Z", "shell.execute_reply": "2023-04-12T16:58:16.057294Z", "shell.execute_reply.started": "2023-04-12T16:58:16.057268Z" } }, "outputs": [], "source": [ "df.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.status.busy": "2023-04-12T16:58:16.060757Z", "iopub.status.idle": "2023-04-12T16:58:16.061301Z", "shell.execute_reply": "2023-04-12T16:58:16.061077Z", "shell.execute_reply.started": "2023-04-12T16:58:16.061046Z" } }, "outputs": [], "source": [ "df3=df[df['country']=='World']\n", "df3" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.status.busy": "2023-04-12T16:58:16.063276Z", "iopub.status.idle": "2023-04-12T16:58:16.064227Z", "shell.execute_reply": "2023-04-12T16:58:16.063828Z", "shell.execute_reply.started": "2023-04-12T16:58:16.063759Z" } }, "outputs": [], "source": [ "df4=df.loc[np.where((temp2['segment']=='Total'))]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.status.busy": "2023-04-12T16:58:16.065727Z", "iopub.status.idle": "2023-04-12T16:58:16.066248Z", "shell.execute_reply": "2023-04-12T16:58:16.066013Z", "shell.execute_reply.started": "2023-04-12T16:58:16.065988Z" } }, "outputs": [], "source": [ "df4" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.status.busy": "2023-04-12T16:58:16.067714Z", "iopub.status.idle": "2023-04-12T16:58:16.068160Z", "shell.execute_reply": "2023-04-12T16:58:16.067963Z", "shell.execute_reply.started": "2023-04-12T16:58:16.067940Z" } }, "outputs": [], "source": [ "'''percent of emission in different type'''\n", "\n", "sns.barplot(data=df3, x='type',y='%percent emission')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T16:59:33.236579Z", "iopub.status.busy": "2023-04-12T16:59:33.236167Z", "iopub.status.idle": "2023-04-12T16:59:33.251999Z", "shell.execute_reply": "2023-04-12T16:59:33.250390Z", "shell.execute_reply.started": "2023-04-12T16:59:33.236541Z" } }, "outputs": [], "source": [ "df.head(3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T17:24:33.032934Z", "iopub.status.busy": "2023-04-12T17:24:33.032539Z", "iopub.status.idle": "2023-04-12T17:24:33.040529Z", "shell.execute_reply": "2023-04-12T17:24:33.038821Z", "shell.execute_reply.started": "2023-04-12T17:24:33.032901Z" } }, "outputs": [], "source": [ "## Segment vs Emissions\n", "\n", "seg_ment=df[~(df['segment']=='Total')]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T17:30:51.442636Z", "iopub.status.busy": "2023-04-12T17:30:51.441947Z", "iopub.status.idle": "2023-04-12T17:30:51.456353Z", "shell.execute_reply": "2023-04-12T17:30:51.455265Z", "shell.execute_reply.started": "2023-04-12T17:30:51.442599Z" } }, "outputs": [], "source": [ "seg=seg_ment.groupby('segment').emissions.sum().reset_index().sort_values(by='emissions',ascending=False,ignore_index=True)[0:10]\n", "seg" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T17:34:34.503946Z", "iopub.status.busy": "2023-04-12T17:34:34.502729Z", "iopub.status.idle": "2023-04-12T17:34:34.597289Z", "shell.execute_reply": "2023-04-12T17:34:34.596324Z", "shell.execute_reply.started": "2023-04-12T17:34:34.503885Z" } }, "outputs": [], "source": [ "fig=px.bar(seg,x='segment',y='emissions',color='segment')\n", "fig.update_layout(title_text='Segment vs Emissions', title_x=0.5)\n", "#fig.update_traces(textposition='inside',textinfo='label+percent')\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T17:36:31.713171Z", "iopub.status.busy": "2023-04-12T17:36:31.712776Z", "iopub.status.idle": "2023-04-12T17:36:31.729242Z", "shell.execute_reply": "2023-04-12T17:36:31.727764Z", "shell.execute_reply.started": "2023-04-12T17:36:31.713135Z" } }, "outputs": [], "source": [ "df.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T17:53:36.314912Z", "iopub.status.busy": "2023-04-12T17:53:36.314533Z", "iopub.status.idle": "2023-04-12T17:53:36.322277Z", "shell.execute_reply": "2023-04-12T17:53:36.321201Z", "shell.execute_reply.started": "2023-04-12T17:53:36.314881Z" } }, "outputs": [], "source": [ "##Emission vs Type analysis\n", "typ=df.groupby('type').emissions.sum().reset_index()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T17:54:34.735945Z", "iopub.status.busy": "2023-04-12T17:54:34.734572Z", "iopub.status.idle": "2023-04-12T17:54:34.783349Z", "shell.execute_reply": "2023-04-12T17:54:34.781882Z", "shell.execute_reply.started": "2023-04-12T17:54:34.735873Z" } }, "outputs": [], "source": [ "fig=px.pie(typ,values='emissions',names='type')\n", "fig.update_traces(textposition='inside',textinfo='label+percent')\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T18:03:53.189333Z", "iopub.status.busy": "2023-04-12T18:03:53.188322Z", "iopub.status.idle": "2023-04-12T18:03:53.202707Z", "shell.execute_reply": "2023-04-12T18:03:53.201174Z", "shell.execute_reply.started": "2023-04-12T18:03:53.189295Z" } }, "outputs": [], "source": [ "##segment and Reason vs Emissions\n", "\n", "sre=df.groupby(['segment','reason']).emissions.sum().reset_index()\n", "se=sre[~(sre['segment']=='Total')]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-04-12T18:11:57.420456Z", "iopub.status.busy": "2023-04-12T18:11:57.419326Z", "iopub.status.idle": "2023-04-12T18:11:57.489845Z", "shell.execute_reply": "2023-04-12T18:11:57.488895Z", "shell.execute_reply.started": "2023-04-12T18:11:57.420385Z" } }, "outputs": [], "source": [ "px.bar(se,x='emissions',y='segment',color='reason')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 4 }