Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Example Analysis of python Air quality data

Shulou Source: shulou.com Published: 2022-06-01 19:10:27 09月30日 Update

This article mainly explains the "python air quality data example analysis", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "python air quality data example analysis" bar!

After calculating the daily average AQI, according to the AQI data, calculate the corresponding daily pollution level, you need to add a new column to the one-month data, and directly add square brackets on the DataFrame.

Monthdata ['level']

In the use of map function, according to the data value of AQI, calculate the corresponding pollution level, map can use the function.

Monthdata ['level'] = monthdata [' AQI'] .map (ComputeLevel)

Aqilevels = np.array ([.])

Levels = np.array ([u 'excellent', u 'good', u 'mild pollution'

U' moderate pollution', u' heavy pollution', u' serious pollution', u' no data'])

Def ComputeLevel (x):

If (not math.isnan (x)):

Index = np.where (aqilevels > = x)

Return levels [index [0] [0]]

Else:

Return'no data'

Fill the part without data with no data, so that it can be easily viewed when the data is counted.

Monthdata ['level'] = monthdata [' level'] .fillna ('innumerable data')

Next, according to the pollution level, count the data in DataFrame and calculate the number of days of each pollution level per month, in which the level column name is converted to count, and level is used as the column name, not as an index.

Levelscount = pd.DataFrame (monthdata ['level'].

Groupby (monthdata ['level']) .count ()

Levelscount = levelscount.rename (columns= {'level':' count'})

Levelscount = levelscount.reset_index ('level')

Use matplotlib to count the number of days at each level per month and display it in a bar chart.

Fig = plt.figure (figsize= (8,5))

Dataax = fig.add_subplot (1,1,1)

Dataax.bar (inde, levelscount ['count'] .tolist ()

0.35, color=lecolor, edgecolor='white') Thank you for your reading, the above is the content of "python Air quality data example Analysis". After the study of this article, I believe you have a deeper understanding of the python air quality data example analysis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Data pollution air quality quality analysis rating learning statistics content function number of days and then inaction lieutenant general middle that is ideas situations parentheses Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology vpn macOS Microsoft Linux