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

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

大家好,我是欧K~

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

涉及到的库:
Pandas — 数据处理
Pyecharts — 数据可视化

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')

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')

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')

2.4 处理风力风向数据

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%",
            )
        )
    )

3.2 2022年历史温度分布

历史最高温度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,
            )
        )
    )

3.4 2019年历史温度分布

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
            ),
        )
    )

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%",
            ),
        )
    )

3.7 2022年白天风向分布

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%",
            ),
        )
    )

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


4. 源码+数据源码下载 | Python可视化系列文章资源(源码+数据)
在线运行地址(含全部代码)

https://www.heywhale.com/mw/project/64926ab8a9796860522c7d8b

END



以上就是本期为大家整理的全部内容了,可以在公众号后台回复【可视化项目源码】获取全部代码+数据喜欢的朋友可以点赞、点在看也可以分享让更多人知道。

相关文章
|
11天前
|
Python
Pandas和pyecharts绘制某天多省区连续确诊病例无新增天数的玫瑰图实战(附源码)
Pandas和pyecharts绘制某天多省区连续确诊病例无新增天数的玫瑰图实战(附源码)
73 0
|
7月前
|
存储 数据可视化 数据挖掘
Pandas和Pyecharts带你揭秘最近热播好剧的主题和题材趋势
Pandas和Pyecharts带你揭秘最近热播好剧的主题和题材趋势
|
9月前
|
数据可视化 数据挖掘 数据处理
Pandas+Pyecharts | 40000+汽车之家数据分析可视化
Pandas+Pyecharts | 40000+汽车之家数据分析可视化
|
9月前
|
数据可视化 数据挖掘 大数据
Pandas+Pyecharts | 北京某平台二手房数据分析可视化
Pandas+Pyecharts | 北京某平台二手房数据分析可视化
|
11天前
|
数据采集 Web App开发 数据可视化
Python爬虫技术与数据可视化:Numpy、pandas、Matplotlib的黄金组合
Python爬虫技术与数据可视化:Numpy、pandas、Matplotlib的黄金组合
|
11天前
|
数据可视化 数据挖掘 定位技术
《Pandas 简易速速上手小册》第9章:Pandas 数据可视化(2024 最新版)
《Pandas 简易速速上手小册》第9章:Pandas 数据可视化(2024 最新版)
39 2
|
11天前
|
JSON JavaScript 数据可视化
数据可视化:将Python的Pandas与Vue结合展示交互式图表
【4月更文挑战第10天】本文探讨了如何利用Python的Pandas库和前端框架Vue.js创建交互式数据可视化应用。通过Pandas进行数据处理和分析,Vue.js构建用户界面,结合两者可实现动态图表展示。步骤包括数据准备、转换为JSON、创建Vue项目、发送数据请求、渲染图表、添加交互性和优化性能。这种结合为数据理解和探索提供了高效、用户友好的解决方案,适应于数据爱好者和专家,预示着未来数据可视化将更智能、互动。
|
11天前
|
数据可视化 数据挖掘 Python
Pandas 高级教程——数据可视化
Pandas 高级教程——数据可视化
99 3
|
11天前
|
数据可视化 Python
利用Pandas探究自行车租赁随时间及天气变化的分布情况并可视化(附源码 超详细)
利用Pandas探究自行车租赁随时间及天气变化的分布情况并可视化(附源码 超详细)
59 1
|
9月前
|
数据可视化 搜索推荐 数据挖掘
Pandas+Pyecharts | 电子产品销售数据分析可视化+用户RFM画像
Pandas+Pyecharts | 电子产品销售数据分析可视化+用户RFM画像