Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
一只猫和一只狗与蟒蛇的发射CO_创想鸟

一只猫和一只狗与蟒蛇的发射CO

嗨,

我发现了一篇关于宠物排放的小文章,因此我决定显示二氧化碳排放(如果它们不存在)。

代码:
https://github.com/victordalet/kaggle_analysis/tree/feat/dog_co2

来源:

https://www.lekaba.fr/article/l-empreinte-carbone-des-chiens-et-des-chats-un-amour-qui-pese-lourd-sur-le-climat

https://www.umweltbundesamt.de/en/image/global-f-gas-emissions-up-to-2050-total

https://www.rover.com/fr/blog/combien-y-a-t-il-de-chats-dans-le-monde/

i-获取数据

首先,我获得了估算世界二氧化碳消耗量、狗和猫的平均排放量以及这些宠物的数量的数据。

import plotly.express as pxclass main:    def __init__(self):        self.estimation = {            "2005": 750,            "2010": 900,            "2020": 1300,            "2030": 1800,            "2040": 2700,            "2050": 4000,        }        self.estimation_no_cat = {            "2005": 750,            "2010": 900,            "2020": 1300,            "2030": 1800,            "2040": 2700,            "2050": 4000,        }        self.estimation_no_dog = {            "2005": 750,            "2010": 900,            "2020": 1300,            "2030": 1800,            "2040": 2700,            "2050": 4000,        }        self.estimation_no_cat_and_dog = {            "2005": 750,            "2010": 900,            "2020": 1300,            "2030": 1800,            "2040": 2700,            "2050": 4000,        }        self.cat_emission = 240        self.dog_emission = 358        self.nb_cats = 600000000        self.nb_dogs = 900000000

二、转型

总排放量以百万吨为单位,因此我创建了一种转换动物数据的方法,单位为公斤。

    @staticmethod    def transform_to_million_of_tonnes(value):        return value / (1000000 * 1000)

iii – 计算

要修改没有猫或狗的估计,请执行第一个估计,并将其他字典的值替换为第一步中找到的值。

    def calculate(self):        for year, value in self.estimation.items():            self.estimation_no_cat[year] = value - self.transform_to_million_of_tonnes(                self.cat_emission * self.nb_cats            )            self.estimation_no_dog[year] = value - self.transform_to_million_of_tonnes(                self.dog_emission * self.nb_dogs            )            self.estimation_no_cat_and_dog[year] = (                value                - self.transform_to_million_of_tonnes(self.cat_emission * self.nb_cats)                - self.transform_to_million_of_tonnes(self.dog_emission * self.nb_dogs)            )

iv – 显示结果

为了显示包含所有数据的图表,我使用了plotly 库。

pip 安装代码:

pip install plotly

显示三个估计值的代码:

    def display(self):        fig = px.line(            x=list(self.estimation.keys()),            y=[                list(self.estimation.values()),                list(self.estimation_no_cat.values()),                list(self.estimation_no_dog.values()),                list(self.estimation_no_cat_and_dog.values()),            ],            labels={                "x": "Year",                "y": "CO2 Emission (in million of tonnes)",                "color": "Legend",            },            title="CO2 Emission with and without cats and dogs",            color_discrete_map={                "CO2 Emission": "blue",                "CO2 Emission without cats": "green",                "CO2 Emission without dogs": "red",                "CO2 Emission without cats and dogs": "orange",            },        )        fig.show()

现在我们有了包含结果的图表。

一只猫和一只狗与蟒蛇的发射CO

以上就是一只猫和一只狗与蟒蛇的发射CO的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1349654.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
好用的json可视化工具下载
上一篇 2025年12月13日 13:00:12
周构建互动游戏
下一篇 2025年12月13日 13:00:32

相关推荐

发表回复

登录后才能评论
关注微信