Skip to content

Instantly share code, notes, and snippets.

@parulnith
Last active February 6, 2020 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parulnith/2d99f3b3bb016cb295ba7677c39cc1e8 to your computer and use it in GitHub Desktop.
Save parulnith/2d99f3b3bb016cb295ba7677c39cc1e8 to your computer and use it in GitHub Desktop.
time_series = df.groupBy(F.year('datetime').alias('year'),
F.weekofyear('datetime').alias('week')) \
.agg(rf_agg_mean('ndvi').alias('mean_ndvi'))
ts_pd = time_series.toPandas()
#Visualizing using matplotlib
ts_pd.sort_values(['year', 'week'], inplace=True)
# Create a compact label of year and week number yyyy_ww
ts_pd['year_week'] = ts_pd.apply(lambda r:'{0:g}_{1:02g}'.format(r.year, r.week), axis=1)
plt.figure(figsize=(10,8))
plt.plot(ts_pd.year_week, ts_pd.mean_ndvi, 'g*-', )
xt = plt.xticks(rotation=-45, )
plt.ylabel('NDVI')
plt.xlabel('Year and week')
plt.title('Sunderbans NDVI')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment