The fog in Beijing is so severe that I have to use Python to analyze a wave! The original PM2.5 early to become less

Source: Internet
Author: User

But with Beijing's vigorous governance, such as sulfur dioxide concentration decreased by 64.3%, the elimination of 1.67 million old motor vehicles, the city six district regulation thousand Beijiexiaoxiang, the original garbage to achieve harmless treatment and so on measures, Beijing PM2.5 down nearly one-fourth, we will eventually win the Blue Sky (source Beijing Entertainment News).

The Baidu Index also gives us the same conclusion. Data from January 2013 to June 2018, the PM2.5 index is significantly lower, it can be said that the yearly decrease.

Environment

Environment: MAC + Python3.6

Ide:spyder

Modules: matplotlib, Pandas, NumPy, OS, Seaborn

Data Set Acquisition

We first read the data set using the Read_csv file in the pandas package. The data set contains the PM values for every one months since 2013, the U.S. Embassy and our country. Then use the basic data method in the pandas package for data preview, including the overall preview of the DataSet, the first 10 lines of view, the basic information of the data file, and so on. The specific code is as follows:

The operation results are as follows

The data set is 26280 rows, 7 columns, occupies 1.4M of memory, the data type is int or float.

Annual average analysis

Based on the data set above, the annual average is analyzed first, and the yearly changes are viewed. The technical points used in this analysis are mainly groupings, that is, grouping by year, and then visualizing the results using a column chart. From the following two figures (PM Chian mean vs PM US mean) can be seen, regardless of the U.S. Embassy or the PM data given by our country, the annual PM value is reduced, indicating that our governance is fruitful, will eventually get the blue sky.

To make it easier to see the comparison of average annual PM2.5 values detected by our national and U.S. embassies, we can visualize them using stacked histogram in Python, as shown in. There is no significant difference in the data given by the two agencies. The specific technical points are mainly the use of the Plot.bar function in the pandas package, but the data must be processed first before visualization. The specific code, can reply PM2.5 obtains.

#堆叠柱状图可视化 Filter_mean.plot.bar (stacked=true) plt.title (' mean PM 2.5 ') plt.tight_layout () Plt.savefig (Os.path.join ( Output_path, ' filter_mean.png ')) Plt.show ()

The visualization results are as follows

Monthly and hourly analysis

From the monthly analysis, the annual November, December and January are the most serious. In the month, the morning and evening rush hour is more serious. The technical point of this visualization is the use of scatter plots.

def analyze_dual_variables (DATA_DF,VAR1,VAR2): "Look at the relationship of Bivariate, scatter plot" ' Sns.jointplot (X=VAR1,Y=VAR2,DATA=DATA_DF) Plt.savefig (Os.path.join (output_path,var1+ ' _ ' +var2+ ' _sandian.png ')) Plt.show ()

Run

You can also use a pivot table to visualize every one-month PM, as follows

Analysis by hour

Correlation analysis

The main technical points used in correlation analysis are heat map, and correlation calculation. Using the Heat force diagram, we can see the similarity of multiple features 22 in the data table, the code is as follows:

def analyze_variable_relationship (DATA_DF): "Visualize variable relationship heat map" #绘制出所有变量直接的关系, form a matrix #corr计算相关系数 corr_df = Data_df.corr () #热图 Sns.heatmap (corr_df,annot=true) plt.savefig (Os.path.join (Output_path, ' heatmap_df.png ')) Plt.show ()

The effect is as follows:

Incoming group: 125240963 to get dozens of sets of PDF books!

The fog in Beijing is so severe that I have to use Python to analyze a wave! The original PM2.5 early to become less

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.