Last active
February 6, 2020 11:06
-
-
Save parulnith/2d99f3b3bb016cb295ba7677c39cc1e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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