【DS实践 | Coursera】Assignment 2 | Applied Plotting, Charting Data Representation in Python
文章目錄
- 一、問題分析
- 1.1 問題描述
- 1.2 問題分析
- 二、具體代碼及注釋
- 2.1 代碼
- 2.2 繪圖結(jié)果
一、問題分析
1.1 問題描述
Before working on this assignment please read these instructions fully. In the submission area, you will notice that you can click the link to Preview the Grading for each step of the assignment. This is the criteria that will be used for peer grading. Please familiarize yourself with the criteria before beginning the assignment.
An NOAA dataset has been stored in the file data/C2A2_data/BinnedCsvs_d400/fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89.csv. This is the dataset to use for this assignment. Note: The data for this assignment comes from a subset of The National Centers for Environmental Information (NCEI) Daily Global Historical Climatology Network (GHCN-Daily). The GHCN-Daily is comprised of daily climate records from thousands of land surface stations across the globe.
Each row in the assignment datafile corresponds to a single observation.
The following variables are provided to you:
- id : station identification code
- date : date in YYYY-MM-DD format (e.g. 2012-01-24 = January 24, 2012)
- element : indicator of element type
- TMAX : Maximum temperature (tenths of degrees C)
- TMIN : Minimum temperature (tenths of degrees C)
- value : data value for element (tenths of degrees C)
For this assignment, you must:
The data you have been given is near Ann Arbor, Michigan, United States, and the stations the data comes from are shown on the map below.
1.2 問題分析
我們發(fā)現(xiàn)該Assignment一共分位四個部分
二、具體代碼及注釋
2.1 代碼
import matplotlib.pyplot as plt import pandas as pd import numpy as np %matplotlib notebook binsize=400 hashid='fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89'#讀取數(shù)據(jù) df=pd.read_csv('data/C2A2_data/BinnedCsvs_d{}/{}.csv'.format(binsize,hashid)) #df=pd.read_csv('assignment2_data.csv')#溫度單位轉(zhuǎn)化 df['value']=df['Data_Value'].apply(lambda x:x/10)#拆分時間 df['year']=pd.to_datetime(df['Date']).apply(lambda x:x.year) df['month']=pd.to_datetime(df['Date']).apply(lambda x:x.month) df['day']=pd.to_datetime(df['Date']).apply(lambda x:x.day)#去除2月29日的數(shù)據(jù) df=df[~((df['month']==2)&(df['day']==29))]#取2005-2014的數(shù)據(jù)為df_05_14 df_05_14=df[(df['year']>=2005)&(df['year']<=2014)] #取2015年的數(shù)據(jù)為df_15 df_15=df[df['year']==2015]#取05-14年數(shù)據(jù)最大值和最小值 df_max_05_14=df_05_14[df_05_14['Element']=='TMAX'].groupby(['month','day']).agg({'value':np.max}) df_min_05_14=df_05_14[df_05_14['Element']=='TMIN'].groupby(['month','day']).agg({'value':np.min})#取15年數(shù)據(jù)最大值和最小值 df_max_15=df_15[df_15['Element']=='TMAX'].groupby(['month','day']).agg({'value':np.max}) df_min_15=df_15[df_15['Element']=='TMIN'].groupby(['month','day']).agg({'value':np.min})#找到打破記錄的日期 broken_max=np.where(df_max_15>df_max_05_14)[0] broken_min=np.where(df_min_15<df_min_05_14)[0]2.2 繪圖結(jié)果
總結(jié)
以上是生活随笔為你收集整理的【DS实践 | Coursera】Assignment 2 | Applied Plotting, Charting Data Representation in Python的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: high-speed Charting
- 下一篇: Coursera | Applied P