Python3 captures and analyzes weather data

Introduction

Use Python to "simplely" grab and analyze weather data.

T_T flipped through the previous article on the official account. . .

Few focus on data visualization analysis. . .

So let's fill in the blanks~~~

Let's Go!

Related documents

File download link: https://pan.baidu.com/s/1dxoxhdu3sqAcNDUKFub0Xg

Password: jc52

development tools

Python version: 3.6.4

Related modules: PIL module; requests module; pyecharts module; and some modules that come with Python.

Environment build

Install Python and add it to the environment variable, and pip installs the required related modules.

Additional Notes:

When installing the pyecharts module, please execute the following commands in sequence:

pip install echarts-countries-pypkg

pip install echarts-china-provinces-pypkg

pip install echarts-china-cities-pypkg

pip install pyecharts

If during installation:

'utf-8' codec can't decode byte 0xb6

Or similar coding error prompts.

You can try to modify the 75th line of code in the __init__.py file under the path shown in the figure below under the Python installation folder:

Modify it as shown in the figure below:

main idea

Use the National Meteorological Administration and Baidu weather query API interface to obtain current weather data, mainly including temperature, humidity, air pressure, etc.

After obtaining the relevant data, use the pyecharts module and the PIL module to perform visual analysis on the data.

See the source code for the specific implementation process.

Result display

use:

Just run the analysis.py file in the cmd window.

What kind of picture do you want to draw? Just remove the corresponding function call comment:

result:

(It is better to open the html file in the related file to view it, and there will be surprises by clicking around~~~)

(1) Air quality in some cities across the country

(2) Simplified map of weather forecast

(3) Histogram of temperature in some cities

(4)部分城市气温折线图

(5)部分城市相对气压饼图

(6)部分城市气温分布图

(7)北京城市湿度

(8)南京天气信息雷达图

有些是为了画图而画图了,所以看起来逻辑很怪T_T

更多

代码截止2018-04-08测试无误。

Echarts作为百度开源的一个数据可视化 JS 库,功能还是十分强大的,有兴趣的朋友可以尝试去绘制一些其他有趣的图表。

Guess you like

Origin blog.csdn.net/m0_67373485/article/details/129787881