目录
1.使用Python折线图对各个城市的P.M.2.5月度差异情况进行数据分析与可视化。
2.使用Python堆叠柱状图对各个城市的PM2.5日均值情况进行数据分析与可视化。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# 公共列
common_cols = ['year', 'month', 'day', 'hour']
# 5个城市
citys = ['beijing', 'chengdu', 'guangzhou', 'shanghai', 'shenyang']
# 数据集部分属性
data_config_dict = {
'beijing': ('Beijing.csv', ['PM_Dongsi', 'PM_Dongsihuan', 'PM_Nongzhanguan'], '北京'),
'chengdu': ('Chengdu.csv', ['PM_Caotangsi', 'PM_Shahepu'], '成都'),
'guangzhou': ('Guangzhou.csv', ['PM_City Station', 'PM_5th Middle School'], '广州'),
'shanghai': ('Shanghai.csv', ['PM_Jingan', 'PM_Xuhui'], '上海'),
'shenyang': ('Shenyang.csv', ['PM_Taiyuanjie', 'PM_Xiaoheyan'], '沈阳')
}
def pct_pol_level(data_arr):
level_1 = data_arr[data_arr <= 50].shape[0]
level_2 = data_arr[data_arr <= 100].shape[0]
level_3 = data_arr[(100 < data_arr) & (data_arr <= 150)].shape[0]
level_4 = data_a