Skip to content

Instantly share code, notes, and snippets.

Created November 23, 2020 06:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
df_ind = df_sd.copy()
df_ind['Date'] = pd.to_datetime(df_ind['Date'],format='%Y-%m-%d')
df_ind['Period'] = df_ind.apply(lambda x: 'Before' if (x['Date'] < dt.datetime(2020, 3, 23)) else 'After',axis=1)
df_ind = df_ind.query('Date>="2020-01-01"')
df_ind = df_ind.groupby(['Period','StationId'],as_index=False)['AQI','PM2.5','PM10','O3','CO','SO2','NO2'].mean()
df_ind = df_ind.merge(df_st[['StationId','StationName','State','Latitude','Longitude']],how='inner',on='StationId')
def scale(aqiSeries):
cmax = aqiSeries.max()
cmin = aqiSeries.min()
dt = 1e-5
good = min((50-cmin)/(cmax-cmin)+dt,1.0)
satisfactory = min((100-cmin)/(cmax-cmin)+dt,1.0)
moderate = min((200-cmin)/(cmax-cmin)+dt,1.0)
poor = min((300-cmin)/(cmax-cmin)+dt,1.0)
very_poor = min((400-cmin)/(cmax-cmin)+dt,1.0)
severe = min((500-cmin)/(cmax-cmin)+dt,1.0)
colorcode = [good,satisfactory,moderate,poor,very_poor,severe]
colorcode = [0.0 if c<0 else c for c in colorcode]
colors = ['#77DD77','#33AF13','#F6D20E','#F17700','#FE6B64','#F12424']
scl = []
prev = 0
for i in range(len(colorcode)):
if colorcode[i]==1.0: break
if scl[-1][0]!=1.0:
return scl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment