0

0

Pandas+Pyecharts | 北京近五年历史天气数据可视化

Python当打之年

Python当打之年

发布时间:2023-08-09 15:29:26

|

1175人浏览过

|

来源于Python当打之年

转载


本期利用 python 的 pyecharts 可视化库绘制北京市历史天气数据,看看历史高温、历史低温分布以及白天、夜晚的风力、风向分布等情况希望对大家有所帮助,如有疑问或者需要改进的地方可以联系小编。

涉及到的库:
pandas — 数据处理
pyecharts — 数据可视化

问问小宇宙
问问小宇宙

问问小宇宙是小宇宙团队出品的播客AI检索工具

下载
1. 导入模块

import pandas as pd
from pyecharts.charts import Line
from pyecharts.charts import Bar
from pyecharts.charts import Scatter
from pyecharts.charts import Pie
from pyecharts.charts import EffectScatter
from pyecharts.charts import Calendar
from pyecharts.charts import Polar
from pyecharts import options as opts
import warnings
warnings.filterwarnings('ignore')
2. Pandas数据处理

2.1 读取数据 

df_weather = pd.read_excel('./2018-2022年天气数据.xlsx')

Pandas+Pyecharts | 北京近五年历史天气数据可视化

2018-2022年五年的历史天气数据共1839条

2.2 处理最低气温最高气温数据

df_weather_1 = df_weather.copy()
df_weather_1[['最低气温','最高气温']] = df_weather_1['最低气温/最高气温'].str.split(' / ',expand=True) 
df_weather_1['最低气温'] = df_weather_1['最低气温'].str[:-2]
df_weather_1['最高气温'] = df_weather_1['最高气温'].str[:-1]
df_weather_1['最低气温'] = df_weather_1['最低气温'].astype('int')
df_weather_1['最高气温'] = df_weather_1['最高气温'].astype('int')

Pandas+Pyecharts | 北京近五年历史天气数据可视化

2.3 处理日期数据

df_weather_1['日期'] = pd.to_datetime(df_weather_1['日期'],format='%Y年%m月%d日')
df_weather_1['日期s'] = df_weather_1['日期'].dt.strftime('%Y/%m/%d')
Pandas+Pyecharts | 北京近五年历史天气数据可视化
2.4 处理风力风向数据

Pandas+Pyecharts | 北京近五年历史天气数据可视化

3. Pyecharts数据可视化

3.1 2018-2022年历史温度分布
def get_scatter():
    scatter = (
        Scatter()
        .add_xaxis(x_data)
        .add_yaxis("最低气温", y_data1)
        .add_yaxis("最高气温", y_data2)
        .set_global_opts(
            legend_opts=opts.LegendOpts(is_show=False),
            visualmap_opts=opts.VisualMapOpts(
                is_show=False,
                range_color=range_color
            ),
            title_opts=opts.TitleOpts(
                title='1-2018-2022年历史温度分布',
                subtitle='-- 制图@公众号:Python当打之年 --',
                pos_top='1%',
                pos_left="1%",
            )
        )
    )

Pandas+Pyecharts | 北京近五年历史天气数据可视化

3.2 2022年历史温度分布

Pandas+Pyecharts | 北京近五年历史天气数据可视化

历史最高温度39℃,历史最低温度-12℃。
3.3 2021年历史温度分布
def get_calendar():
    calendar = (
        Calendar()
        .add('',
             data_21,
             calendar_opts=opts.CalendarOpts(
                 pos_right='5%',
                 range_='2021',
                daylabel_opts=opts.CalendarDayLabelOpts(name_map='cn'),
                monthlabel_opts=opts.CalendarMonthLabelOpts(name_map='cn')
             ),
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title='3-2021年历史温度分布',
                subtitle='-- 制图@公众号:Python当打之年 --',
                pos_top='1%',
                pos_left="1%",
            ),
            visualmap_opts=opts.VisualMapOpts(
                range_color=range_color,
            )
        )
    )

Pandas+Pyecharts | 北京近五年历史天气数据可视化

3.4 2019年历史温度分布
Pandas+Pyecharts | 北京近五年历史天气数据可视化

3.5 2022年夜间_白天风力分布

def get_pie():
    pie = (
        Pie()
        .add(
            "",
            [list(z) for z in zip(x_data, y_data1)],
            radius=["30%", "50%"],
            center=["30%", "55%"],
        )
        .add(
            "",
            [list(z) for z in zip(x_data, y_data2)],
            radius=["30%", "50%"],
            center=["70%", "55%"],
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title='5-2022年夜间_白天风力分布',
                subtitle='-- 制图@公众号:Python当打之年 --',
                pos_top='1%',
                pos_left="1%",
            ),
            legend_opts=opts.LegendOpts(pos_top='10%'),
            visualmap_opts=opts.VisualMapOpts(
                is_show=False,
                range_color=range_color
            ),
        )
    )

Pandas+Pyecharts | 北京近五年历史天气数据可视化

3.6 2022年夜间风向分布
def get_polor():
    polor = (
        Polar()
        .add("", values,type_="bar")
        .set_global_opts(
            legend_opts=opts.LegendOpts(is_show=False),
            visualmap_opts=opts.VisualMapOpts(
                is_show=False,
                range_color=range_color
            ),
            title_opts=opts.TitleOpts(
                title='6-2022年夜间风向分布',
                subtitle='-- 制图@公众号:Python当打之年 --',
                pos_top='1%',
                pos_left="1%",
            ),
        )
    )
Pandas+Pyecharts | 北京近五年历史天气数据可视化

3.7 2022年白天风向分布

Pandas+Pyecharts | 北京近五年历史天气数据可视化

3.8 2018-2022年各类型天气数量

def get_bar():
    bar = (
        Bar()
        .add_xaxis(x_data)
        .add_yaxis("",y_data)
        .set_global_opts(
            visualmap_opts=opts.VisualMapOpts(
                is_show=False,
                range_color=range_color
            ),
            legend_opts=opts.LegendOpts(is_show=False),
            title_opts=opts.TitleOpts(
                title='8-2018-2022年各类型天气数量',
                subtitle='-- 制图@公众号:Python当打之年 --',
                pos_top='1%',
                pos_left="1%",
            ),
        )
    )
Pandas+Pyecharts | 北京近五年历史天气数据可视化

3.9 2018-2022年每月平均最高温度

Pandas+Pyecharts | 北京近五年历史天气数据可视化

相关专题

更多
苹果官网入口直接访问
苹果官网入口直接访问

苹果官网直接访问入口是https://www.apple.com/cn/,该页面具备0.8秒首屏渲染、HTTP/3与Brotli加速、WebP+AVIF双格式图片、免登录浏览全参数等特性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

115

2025.12.24

拼豆图纸在线生成器
拼豆图纸在线生成器

拼豆图纸生成器有PixelBeads在线版、BeadGen和“豆图快转”;推荐通过pixelbeads.online或搜索“beadgen free online”直达官网,避开需注册的诱导页面。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

82

2025.12.24

俄罗斯搜索引擎yandex官方入口地址(最新版)
俄罗斯搜索引擎yandex官方入口地址(最新版)

Yandex官方入口网址是https://yandex.com。用户可通过网页端直连或移动端浏览器直接访问,无需登录即可使用搜索、图片、新闻、地图等全部基础功能,并支持多语种检索与静态资源精准筛选。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

546

2025.12.24

JavaScript ES6新特性
JavaScript ES6新特性

ES6是JavaScript的根本性升级,引入let/const实现块级作用域、箭头函数解决this绑定问题、解构赋值与模板字符串简化数据处理、对象简写与模块化提升代码可读性与组织性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

150

2025.12.24

php框架基础知识汇总
php框架基础知识汇总

php框架是构建web应用程序的架构,提供工具和功能,以简化开发过程。选择合适的框架取决于项目需求和技能水平。实战案例展示了使用laravel构建博客的步骤,包括安装、创建模型、定义路由、编写控制器和呈现视图。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

20

2025.12.24

Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

47

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

7

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

12

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

371

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Pandas 教程
Pandas 教程

共15课时 | 0.8万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号