{"id":205285,"date":"2025-05-29T12:28:07","date_gmt":"2025-05-29T04:28:07","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205285\/"},"modified":"2025-05-29T12:28:07","modified_gmt":"2025-05-29T04:28:07","slug":"%e4%b8%80%e5%8f%aa%e7%8c%ab%e5%92%8c%e4%b8%80%e5%8f%aa%e7%8b%97%e4%b8%8e%e8%9f%92%e8%9b%87%e7%9a%84%e5%8f%91%e5%b0%84co","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205285\/","title":{"rendered":"\u4e00\u53ea\u732b\u548c\u4e00\u53ea\u72d7\u4e0e\u87d2\u86c7\u7684\u53d1\u5c04CO"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u4e00\u53ea\u732b\u548c\u4e00\u53ea\u72d7\u4e0e\u87d2\u86c7\u7684\u53d1\u5c04CO<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u5bf9\u6587\u7ae0\u7f16\u7a0b\u611f\u5174\u8da3\u5417\uff1f\u662f\u5426\u6b63\u5728\u5b66\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff1f\u5982\u679c\u662f\uff0c\u90a3\u4e48\u672c\u6587\u300a\u4e00\u53ea\u732b\u548c\u4e00\u53ea\u72d7\u4e0e\u87d2\u86c7\u7684\u53d1\u5c04CO\u300b\uff0c\u5c31\u5f88\u9002\u5408\u4f60\uff0c\u672c\u7bc7\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\u3002\u5728\u4e4b\u540e\u7684\u6587\u7ae0\u4e2d\u4e5f\u4f1a\u591a\u591a\u5206\u4eab\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>\u55e8\uff0c<\/p>\n<p>\u6211\u53d1\u73b0\u4e86\u4e00\u7bc7\u5173\u4e8e\u5ba0\u7269\u6392\u653e\u7684\u5c0f\u6587\u7ae0\uff0c\u56e0\u6b64\u6211\u51b3\u5b9a\u663e\u793a\u4e8c\u6c27\u5316\u78b3\u6392\u653e\uff08\u5982\u679c\u5b83\u4eec\u4e0d\u5b58\u5728\uff09\u3002<\/p>\n<p>\u4ee3\u7801\uff1a<br \/> https:\/\/github.com\/victordalet\/kaggle_analysis\/tree\/feat\/dog_co2<\/p>\n<p>\u6765\u6e90\uff1a<\/p>\n<ul>\n<li>\n<p>https:\/\/www.lekaba.fr\/article\/l-empreinte-carbone-des-chiens-et-des-chats-un-amour-qui-pese-lourd-sur-le-climat<\/p>\n<\/li>\n<li>\n<p>https:\/\/www.umweltbundesamt.de\/en\/image\/global-f-gas-emissions-up-to-2050-total<\/p>\n<\/li>\n<li>\n<p>https:\/\/www.rover.com\/fr\/blog\/combien-y-a-t-il-de-chats-dans-le-monde\/<\/p>\n<\/li>\n<\/ul>\n<hr>\n<p>\u9996\u5148\uff0c\u6211\u83b7\u5f97\u4e86\u4f30\u7b97\u4e16\u754c\u4e8c\u6c27\u5316\u78b3\u6d88\u8017\u91cf\u3001\u72d7\u548c\u732b\u7684\u5e73\u5747\u6392\u653e\u91cf\u4ee5\u53ca\u8fd9\u4e9b\u5ba0\u7269\u7684\u6570\u91cf\u7684\u6570\u636e\u3002<\/p>\n<pre>import plotly.express as px\n\n\nclass main:\n    def __init__(self):\n        self.estimation = {\n            \"2005\": 750,\n            \"2010\": 900,\n            \"2020\": 1300,\n            \"2030\": 1800,\n            \"2040\": 2700,\n            \"2050\": 4000,\n        }\n\n        self.estimation_no_cat = {\n            \"2005\": 750,\n            \"2010\": 900,\n            \"2020\": 1300,\n            \"2030\": 1800,\n            \"2040\": 2700,\n            \"2050\": 4000,\n        }\n\n        self.estimation_no_dog = {\n            \"2005\": 750,\n            \"2010\": 900,\n            \"2020\": 1300,\n            \"2030\": 1800,\n            \"2040\": 2700,\n            \"2050\": 4000,\n        }\n\n        self.estimation_no_cat_and_dog = {\n            \"2005\": 750,\n            \"2010\": 900,\n            \"2020\": 1300,\n            \"2030\": 1800,\n            \"2040\": 2700,\n            \"2050\": 4000,\n        }\n\n        self.cat_emission = 240\n        self.dog_emission = 358\n        self.nb_cats = 600000000\n        self.nb_dogs = 900000000\n<\/pre>\n<p>\u603b\u6392\u653e\u91cf\u4ee5\u767e\u4e07\u5428\u4e3a\u5355\u4f4d\uff0c\u56e0\u6b64\u6211\u521b\u5efa\u4e86\u4e00\u79cd\u8f6c\u6362\u52a8\u7269\u6570\u636e\u7684\u65b9\u6cd5\uff0c\u5355\u4f4d\u4e3a\u516c\u65a4\u3002<\/p>\n<pre>    @staticmethod\n    def transform_to_million_of_tonnes(value):\n        return value \/ (1000000 * 1000)\n<\/pre>\n<p>\u8981\u4fee\u6539\u6ca1\u6709\u732b\u6216\u72d7\u7684\u4f30\u8ba1\uff0c\u8bf7\u6267\u884c\u7b2c\u4e00\u4e2a\u4f30\u8ba1\uff0c\u5e76\u5c06\u5176\u4ed6\u5b57\u5178\u7684\u503c\u66ff\u6362\u4e3a\u7b2c\u4e00\u6b65\u4e2d\u627e\u5230\u7684\u503c\u3002<\/p>\n<pre>    def calculate(self):\n        for year, value in self.estimation.items():\n            self.estimation_no_cat[year] = value - self.transform_to_million_of_tonnes(\n                self.cat_emission * self.nb_cats\n            )\n            self.estimation_no_dog[year] = value - self.transform_to_million_of_tonnes(\n                self.dog_emission * self.nb_dogs\n            )\n            self.estimation_no_cat_and_dog[year] = (\n                value\n                - self.transform_to_million_of_tonnes(self.cat_emission * self.nb_cats)\n                - self.transform_to_million_of_tonnes(self.dog_emission * self.nb_dogs)\n            )\n<\/pre>\n<p>\u4e3a\u4e86\u663e\u793a\u5305\u542b\u6240\u6709\u6570\u636e\u7684\u56fe\u8868\uff0c\u6211\u4f7f\u7528\u4e86plotly \u5e93\u3002<\/p>\n<p>pip \u5b89\u88c5\u4ee3\u7801\uff1a<\/p>\n<pre>pip install plotly\n<\/pre>\n<p>\u663e\u793a\u4e09\u4e2a\u4f30\u8ba1\u503c\u7684\u4ee3\u7801\uff1a<\/p>\n<pre>    def display(self):\n        fig = px.line(\n            x=list(self.estimation.keys()),\n            y=[\n                list(self.estimation.values()),\n                list(self.estimation_no_cat.values()),\n                list(self.estimation_no_dog.values()),\n                list(self.estimation_no_cat_and_dog.values()),\n            ],\n            labels={\n                \"x\": \"Year\",\n                \"y\": \"CO2 Emission (in million of tonnes)\",\n                \"color\": \"Legend\",\n            },\n            title=\"CO2 Emission with and without cats and dogs\",\n            color_discrete_map={\n                \"CO2 Emission\": \"blue\",\n                \"CO2 Emission without cats\": \"green\",\n                \"CO2 Emission without dogs\": \"red\",\n                \"CO2 Emission without cats and dogs\": \"orange\",\n            },\n        )\n        fig.show()\n<\/pre>\n<p>\u73b0\u5728\u6211\u4eec\u6709\u4e86\u5305\u542b\u7ed3\u679c\u7684\u56fe\u8868\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241128\/17327586056747cc4daf1cb.png\" class=\"aligncenter\"><\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u53ea\u732b\u548c\u4e00\u53ea\u72d7\u4e0e\u87d2\u86c7\u7684\u53d1\u5c04CO &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205285","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205285"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205285\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}